|
| Previous: 2.6.7 Conjunctions and Disjunctions | TOC | Index | Back | Next: 2.6.9 Constant Expressions |
The ternary conditional operator has the least precedence. Therefore, it may be used to combine any kind of expressions without using parentheses. The following expression, for example, implements the minimum function:
a<b -> a : b
Since the operator has three operands, it consists of two parts: '->' and ':'. The meaning of the conditional operator is as follows: Given is the expression
A-> B: C
If the operand A (the condition) evaluates to some `true' value, B will be evaluated and otherwise, C will be evaluated. If B is evaluated, C will not be evaluated and vice versa. The result of the expression is equal to the value of the most recently evaluated operand.
Like the logical operators /\ and \/, the conditional operator has a connection to conditional statements:
A-> B(): C()
is equivalent to
IE (A) B(); ELSE C();
except for the fact, of course, that the expression has a value, while the statement only has a side effect. IE means If/Else and introduces a conditional statement with an alternative. The IE statement will be discussed in a later section.
| Previous: 2.6.7 Conjunctions and Disjunctions | TOC | Index | Back | Next: 2.6.9 Constant Expressions |