In the following example, E, E1, and so on, are expressions. When control reaches the SELECT statement, the expression E is evaluated and its value is saved. The expressions in the WHEN statements are then evaluated in turn (in the order in which they appear), and each value is compared with the value of E.
If a value is found that is equal to the value of E, the action following the corresponding THEN statement is performed; no further WHEN statement expressions are evaluated.
If none of the expressions in the WHEN statements are equal to the expression in the SELECT statement, the action specified after the OTHERWISE statement is executed.
select (E);
when (E1,E2,E3) action-1;
when (E4,E5) action-2;
otherwise action-n;
end;
Nl: next statement;
An example of exp1 being omitted is:
select;
when (A>B) call Bigger;
when (A=B) call Same;
otherwise call Smaller;
end;
If a select-group contains no WHEN statements, the action in the OTHERWISE statement is executed unconditionally. If the OTHERWISE statement is omitted, and execution of the select-group does not result in the selection of a WHEN statement, the ERROR condition is raised.