TAL Programmer's Guide

CASE Statement, Labeled
Controlling Program Flow
12–6 096254 Tandem Computers Incorporated
For example, this labeled CASE statement has four case-alternatives and the
OTHERWISE clause:
INT location;
LITERAL bay_area, los_angeles, hawaii, elsewhere;
PROC area_proc (area_code); !Declare procedure
INT area_code; !Declare
selector
as
BEGIN ! formal parameter
CASE area_code OF !
Selector
is AREA_CODE
BEGIN
408, 415 ->
location := bay_area;
213, 818 ->
location := los_angeles;
808 ->
location := hawaii;
OTHERWISE ->
location := elsewhere;
END; !End CASE statement
END; !End AREA_PROC
Statement Forms
Generated by the Compiler
The compiler generates a branch table form or a conditional test form of the labeled
CASE statement, depending on the maximum range and number of case label values:
The compiler generates a branch table form if the maximum range (between the
smallest and largest case labels) is either:
Less than 257
Between 257 and 2048 inclusive and the approximate number of words of code
for the branch table form (maximum range + 12) is no greater than the
approximate number of words of code for the conditional test form (number
of labels * 13 + 2)
In all other cases, the compiler generates a conditional test form. If the statement
has more than 63 case labels, the compiler issues an error.
The branch table form is much faster than the conditional test form.
To improve the efficiency of the conditional test form, you can order the alternatives
from most common to least common.