pTAL Conversion Guide

Statements
pTAL Conversion Guide527302-002
15-9
CASE Statement Operation When No Alternatives
Match the Index
TAL
The behavior of a CASE statement that does not have an OTHERWISE alternative
depends on:
The current setting of the CHECK directive
Whether the statement is a labeled or unlabeled CASE statement
For labeled and unlabeled CASE statements, if the case index does not match any
alternative, but an OTHERWISE alternative is present, execution continues with the
statements associated with the OTHERWISE alternative.
If a case index does not match any of the case alternatives and an OTHERWISE
alternative is not provided, program action following the CASE statement is as follows:
A labeled CASE statement and an unlabeled CASE statement that are compiled
while the CHECK directive is in effect cause a divide-by-zero exception. If traps are
disabled, program execution continues with the statement that follows the CASE
statement.
An unlabeled CASE statement compiled while the CHECK directive is not in effect
(NOCHECK is specified) produces undefined results.
pTAL
A case index that does not match any alternative (including an OTHERWISE
alternative) causes an instruction trap, regardless of the value of the CHECK directive.
Control transfers to system code.
Example 15-9. CASE Index That Matches No Alternatives
LITERAL apple, orange, pear, peach, prune;
INT i;
i := peach; ! Set index value
CASE i OF
BEGIN
apple -> CALL p1;
orange -> CALL p2;
prune -> CALL p3;
OTHERWISE -> CALL p4; ! Executes this alternative
END;
Note. The native compiler recognizes the CHECK directive but CHECK does not affect the
behavior of a labeled or unlabeled CASE statement. See Section 19, Compiler Operation, for
more information about the CHECK directive.