TAL Reference Manual

Statements
TAL Reference Manual526371-001
12-14
Examples of Unlabeled CASE Statements
selector is 4, the fifth statement executes. Conversely, if the selector does not match a
compiler-assigned number, the OTHERWISE
statement, if any, executes.
For unlabeled CASE statements, the compiler always generates the branch table form
(described in “Labeled CASE Statement” in the
TAL Programmer’s Guide).
Omitted Otherwise Clause
If you omit the OTHERWISE clause and selector is out of range (negative or greater
than n), the compiler behaves as follows:
If the CHECK directive is in effect and your program enables arithmetic traps, a
divide-by-zero instruction trap occurs.
If NOCHECK is in effect or if your program disables arithmetic traps, control
passes to the statement following the unlabeled CASE statement and program
results are unpredictable.
Examples of Unlabeled CASE Statements
1. If SELECTOR in the following CASE statement is 0, the first statement executes; if
SELECTOR is 1, the second
statement executes. For any other SELECTOR value,
the third
statement executes:
INT selector;
INT var0;
INT var1;
CASE selector OF
BEGIN
var0 := 0; !First statement
var1 := 1; !Second statement
OTHERWISE
CALL error_handler; !Third statement
END;
2. This example selectively moves one of several messages into an array:
PROC msg_handler (selector);
INT selector;
BEGIN
LITERAL len = 80; !Length of array
STRING .a_array[0:len - 1]; !Destination array