Case expressions provide a means of selecting one expression form a list of expressions for evaluation.
<case expression>
──┬─<arithmetic case expression>────┬──────────────────────────────────┤ ├─<Boolean case expression>───────┤ ├─<complex case expression>───────┤ ├─<designational case expression>─┤ └─<pointer case expression>───────┘
In a case expression, the list of expressions must be composed of expressions of the same kind: for example, all arithmetic expressions or all Boolean expressions. The expression to be evaluated is selected as follows:
-
The arithmetic expression in the case head is evaluated and rounded by an integer value, if necessary.
-
This value is used as an index into the expression list. The component expressions of the expression list are numbered sequentially from 0 through N–1, where N is the number of expressions in the list.
-
The expression selected by the index is evaluated, and its value is the value of the case expression.
If the value of the index lies outside the range 0 through N–1, the program is discontinued with a fault.
The type of an arithmetic case expression is DOUBLE if any of its constituent expressions is of type DINTEGER or DOUBLE; in this case, any constituent expression that is not of type DOUBLE is extended to double-precision. The type of an arithmetic case expression is INTEGER if and only if all of its constituent expressions are of type INTEGER. Otherwise, an arithmetic case expression is of type REAL.
Examples of Case Expressions
CASE N OF (2, 20, 100, 37) CASE X.[27:2] OF (TRUE, FALSE, TRUE, TRUE) CASE I OF (C1, C2, COMPLEX(X,Y)) CASE TSTS[INDEX] OF (LBL1, LBL2, AGAIN, NEXT, MORE) CASE CHAR.SZF OF (PTR, PTS, POINTER(A), PTEMP, POLO)

