Case statement
SYNTAX:
case_stmt = CASE selector OF { case_action } [ OTHERWISE ':' stmt ]Â Â END_CASE ';' .
selector = expression .
case_action = case_label { ',' case_label } ':' stmt .
case_label = expression .
The case statement is a mechanism for selectively executing statements based on the value of an expression. A statement is executed depending on the value of the selector. The case statement consists of an expression, which is the case selector, and a list of alternative actions, each one preceded by one or more expressions, which are the case labels. The evaluated type of the case label shall be compatible with the type of the case selector. The first occurring statement having a case label that evaluates to the same value as the case selector is executed. At most, one case-action is executed. If none of the case labels evaluates to the same value as the case selector either a) or b) will happen.
- if the otherwise clause is present, the statement associated with otherwise is executed.
- if the otherwise clause is not present, no statement associated with the case action is executed.
Rules and restrictions:
The type of the evaluated value of the case labels shall be compatible with the type of the evaluated value of the case selector.
Example
(* A simple case statement using integer case labels. *)
Â
LOCAL
 a : INTEGER ;
 x : REAL ;
END_LOCAL ;
...
a :=3;
x := 34.97 ;
Â
CASE a OF
 1    : x := SIN ;
 2    : x := EXP ;
 3    : x := SQRT ; – This is executed!
 4, 5   : x := LOG ;
 OTHERWISE : x := 0.0 ;
END_CASE ;