Conditional expressions are expressions that return one of two possible values, depending upon a specified condition.
<conditional expression>
──┬─<conditional arithmetic expression>────┬───────────────────────────┤ ├─<conditional Boolean expression>───────┤ ├─<conditional complex expression>───────┤ ├─<conditional designational expression>─┤ └─<conditional pointer expression>───────┘
Conditional expressions are of the following form:
IF <Boolean expression> THEN <expression> ELSE <expression>
Either the first or the second expression is selected for evaluation, depending on the value of the Boolean expression. The two alternative expressions must be of the same kind: for example, two arithmetic expressions or two Boolean expressions.
The expression to be evaluated is selected as follows:
-
The Boolean expression following IF is evaluated.
-
If the resulting value is TRUE, the expression following THEN is evaluated, and the expression following ELSE is ignored.
-
If the resulting value is FALSE, the expression following THEN is ignored, and the expression following ELSE is evaluated.
If either of the two expressions is itself a conditional expression, the process is repeated until an unconditional expression is selected for evaluation.
The type of a conditional arithmetic expression is DOUBLE if either of its constituent expressions is of type DINTEGER or DOUBLE; in this case, a constituent expression that is not of type DOUBLE is extended to double-precision. The type of a conditional arithmetic expression is INTEGER if and only if both of its constituent expressions are of type INTEGER. Otherwise, a conditional arithmetic expression is of type REAL.
Examples of Conditional Expressions
IF BOOL THEN 47 ELSE 95 IF A = B THEN BOOL ELSE FALSE IF NOT BOOL THEN C1 ELSE C2 IF ALLDONE THEN EOJLBL ELSE NEXTLBL IF CHAR.SZF = 8 THEN PTRINEBCDIC ELSE PTRINHEX

