Conditional
Run a different diagram for each condition. Create branches, define their ports, and wire them on the canvas.
A Conditional checks IF, then any ELIF branches, from top to bottom. Only the first matching branch runs. ELSE runs when none match. Use If-Then-Else when you only need to select between two already-computed signals.
Build a command gate
When enabled is true, pass command to result. Otherwise, output 0.
All steps in text
- Drag Conditional from the block library onto the canvas and select it.
- In Branches & ports, name IF
Activeand set its condition toenabled. Press Enter to save the condition. Add inputcommandand outputresult, then choose Apply interface. Open ELSE, name itFallback, and add outputresult. Apply this interface too. - Double-click Active on the canvas. Connect the automatically created Virtual Input
commandto Virtual Outputresult. Return through the breadcrumb, open Fallback, and connect a Constant with value0to itsresultoutput. Usefloat64for bothresultoutputs and their connected values in this example. - Return to the parent canvas. Connect a boolean signal to
enabledon top, a numeric signal tocommandon the left, and takeresultfrom the right. Test both values ofenabled: true passes the command; false returns zero.
Read the ports
- Top — condition inputs. Typing
enabledin the condition exposes a data input with that name. Connect a boolean signal for this example. - Left — branch inputs. Inputs are grouped by IF, ELIF, and ELSE. A port belongs to its labeled branch; identical names in different branches are separate connections.
- Right — shared outputs. Both branches write to the same parent port,
result. The selected branch decides its value.
Give branches the same outputs
For each shared output, use the same name, data type, and dimensions in every branch. The value can change; the output interface stays the same.
For the command gate, configure and wire:
| Branch | Output name | Type / shape | Value it supplies |
|---|---|---|---|
| IF · Active | result | float64, scalar | The incoming command |
| ELSE · Fallback | result | float64, scalar | Constant 0 |
The parent canvas shows one result port. With command = 12, it outputs 12 when enabled and 0 otherwise.
- Copy the output name exactly.
resultandfallback_resultcreate two separate parent ports; they do not become alternatives for one output. - Match the connected values too. A scalar and a vector, or
float64andint32, cannot be merged as-is. Make the connected signals the same type and shape first; the output does not convert them for you. - Wire the output inside every branch, including ELSE. Adding its name creates the Virtual Output block; it does not connect it. A missing branch output is not an automatic zero. For a zero fallback, connect a Constant
0.
Branch inputs may differ: Active needs command; Fallback only needs its Constant.
Write a condition
Click the branch’s Condition field and enter one expression that answers true or false. Press Enter to save. ELSE has no editable condition; it is the fallback.
| You want to check | Write | Inputs to connect on top |
|---|---|---|
| A boolean signal is true | enabled | enabled (bool) |
| A value exceeds a limit | speed > 10 | speed (numeric) |
| Two values are equal | mode == 2 | mode (numeric in this example) |
| Both conditions hold | enabled and speed > limit | enabled (bool), speed and limit (numeric) |
| Either condition holds | speed < 0 or speed > 100 | speed (numeric) |
| A boolean signal is false | not fault | fault (bool) |
| A calculated comparison holds | (target - actual) * gain > 0.5 | target, actual, gain (numeric) |
Allowed syntax: numbers (including -2, 0.5, 1e-3), true / false, input names, arithmetic + - * /, comparisons == != < <= > >=, boolean operators and or not, and parentheses. Use parentheses to make grouping explicit, such as enabled and (speed > 10 or override).
Where do the names come from?
Typing speed > limit exposes two condition inputs on the top of the Conditional. Connect the speed signal to speed and the threshold signal to limit. Names are case-sensitive; use letters, digits, and underscores, starting with a letter or underscore.
To use a parameter, feed it through a Constant block: set its value to your $parameter reference, connect it to the top limit input, then write speed > limit. Do not put $parameter directly in the condition. A branch input with the same name on the left is a separate port; wire the top input for the condition as well.
Common fixes
| Instead of | Use |
|---|---|
speed = 10 | speed == 10 — equality uses two equals signs |
enabled && ready or !fault | enabled and ready or not fault |
speed when speed is numeric | speed > 0 — numbers are not implicitly true or false |
0 < speed < 100 | speed > 0 and speed < 100 |
Conditions do not support function calls such as abs(speed), strings, %, **, array indexing, or member access such as Mode.SPORT. Calculate those values with blocks first, then connect the result as a condition input.
“Valid” confirms the expression’s syntax. It does not confirm that every input is connected or correctly typed; those checks happen when the model is validated or built.
Add or edit branches
Choose + Add elif to insert another condition before ELSE. Order matters: the first true condition wins. An IF condition of true always selects IF, so later branches will never run.
Expand a branch to add, rename, or remove ports, then choose Apply interface. Modeloop updates the corresponding Virtual Input/Output blocks inside it. Child-side edits synchronize back to the parent too. When renaming a shared output, update its name in each branch so it remains one parent output.
Renaming a port preserves its wiring; removing it removes attached connections. Undo restores an applied interface edit. Collapsing a branch preserves unfinished port edits; Cancel discards them.