TAL Programmer's Guide
CASE Statement, Labeled
Controlling Program Flow
096254 Tandem Computers Incorporated 12–5
CASE Statement,
Labeled
A labeled CASE statement consists of a selector and a series of case alternatives. Each
alternative associates one or more case labels with a set of statements. When the
selector matches a case label, the associated set of statements executes.
The unlabeled CASE statement is described in the TAL Reference Manual.
To specify a labeled CASE statement, include:
CASE selector OF BEGIN
Specifies a value that selects the case-alternative to execute. The selector must be an
INT arithmetic expression; for example:
INT i; !Declare INT variable I
!Code to initialize I
CASE i OF BEGIN ... !Selector is I
case-alternatives
Each case-alternative specifies a choice of statements to execute when the selector
matches a case-label. You can specify any number of case-alternatives; at least one is
required. Each case-alternative consists of:
case-labels ->
One or more INT constants in any order, separated by commas, followed by
->. To include a case-label as a range of constants, specify the lowest and
highest values separated by two periods (..):
2, 9, 4 .. 7, 11 -> !Case labels 2, 4, 5, 6, 7,
! and 9 for one alternative
statements
One or more statements to execute if the selector matches any case-label in this
alternative:
2, 9, 4 .. 7 -> !Case labels
aa := cc + dd; !When I is 2 or 9 or any of
bb := cc – dd; ! 4 through 7, execute these
! statements
OTHERWISE –> statements
An optional clause that specifies optional statements to execute if the selector does
not match any case-label in the CASE statement. If no OTHERWISE clause is
present and the selector does not match a case-label, a run-time error results. So
always include the OTHERWISE clause, even if it contains no statements.
END
Specifies the end of the CASE statement.