pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
case-alternative
associates one or more case-label s or one or more ranges of case-label s with one or
more statement s. The statement s of a case-alternative are executed if selector
equals an associated case-label. Each case-alternative has the form:
case-label
a signed INT constant or LITERAL. Each case-label must be unique in the CASE statement.
lower-case-label
is the smallest value in an inclusive range of signed INT constants or LITERALs.
upper-case-label
is the largest value in an inclusive range of signed INT constants or LITERALs.
statement-1
is any statement described in this section.
OTHERWISE
specifies an optional sequence of statements to execute if selector does not select any
case-alternative. If no OTHERWISE clause is present and selector does not match
a case-alternative, a run-time error occurs. Always include an OTHERWISE clause, even
if it contains no statements.
statement-2
is any statement described in this section.
A CASE statement must have at least one alternative.
If you omit the OTHERWISE clause and selector is out of range (negative or greater than n),
the a divide-by-zero instruction trap occurs.
A CASE index matches an alternative identified by the keyword OTHERWISE if and only if the
case index does not match any other alternative and OTHERWISE is an alternative.
Example 148 Labeled CASE Statement
LITERAL apple, orange, pear, peach, prune;
INT i;
i := peach; ! Set index value
CASE i OF ! Execute CASE
BEGIN
apple -> CALL p1;
orange -> CALL p2;
prune -> CALL p3;
OTHERWISE -> CALL p4; ! Execute this alternative
END;
Example 149 Labeled CASE Statement
INT location;
LITERAL bay_area, los_angeles, hawaii, elsewhere;
PROC area_proc (area_code);
INT area_code; ! Declare selector as
208 Statements