Conditional Operators

Note

Only available in the block diagram editor for software components.

The following conditional operators are available:

The conditional operator ( ? : ) is named Multiplex operator (for short: Mux) in the graphical representation.

ClosedEXAMPLE

The graphical representation of

(condition ? trueValue : falseValue)

is as follows:

The multiplex operator can also be used directly with several arguments (left image), the right image shows the identical functionality built as a cascade of several Mux operators:

The above example is equivalent to

(condition1 ? (true1Value : condition2 ? ( false1true2Value : false1false2Value))),

i.e., the first argument has priority over the others. A cascaded Mux operator with n logical condition arguments can select between n+1 arguments between which it switches. The type of the arguments is arbitrary, but all arguments must be of a compatible type.

The Case operator is a special case of the conditional operator. It does not take a logical value, but a switch value of discrete type (see also Scalar Types – Summary). The Case operator has n arguments, n-1 of which are numbered consecutively. The last argument is the default case.

Depending on the switch value, one of the arguments is selected. If the switch value is 1, the first argument is returned, if it is 2 the second is returned, and so on. If the switch value is less than 1, or n, or larger than n, the last argument is returned.

ClosedEXAMPLE

The above example is equivalent to

switch (self->switch_value->val)
{
case 1 :
 {
   out_case = case_1;
   break;
 }
case 2 :
 {
   out_case = case_2;
   break;
 }
default:
 {
   out_case = case_default;
   break;
 }
}

See also

Arithmetic Operators

Logical Operators

Comparison Operators

Input Operators

Negation Operator

Control Flow Operators

Miscellaneous Basic Blocks