TAL Programmer's Guide

IF Statement
Controlling Program Flow
12–4 096254 Tandem Computers Incorporated
IF-ELSE Pairing You can nest IF statements to any level. In a nested IF statement, the innermost IF
clause pairs with the closest ELSE clause. Formatting can make the IF-ELSE pairing
obvious or ambiguous.
The following side-by-side examples are equivalent. In both cases, the ELSE clause
belongs to the second IF statement, but the pairing is clearer in the example on the left:
Recommended Format Unclear Format
IF expression1 THEN IF expression1 THEN
IF expression2 THEN IF expression2 THEN stmt1
stmt1 ELSE stmt2;
ELSE
stmt2;
To override the default IF-ELSE pairing, you can use the BEGIN-END construct. For
example, if you insert a BEGIN-END pair in the preceding example, the ELSE clause
belongs to the first IF clause rather than to the second IF clause:
IF expression1 THEN
BEGIN !Begin compound statement
IF expression2 THEN
stmt1;
END !End compound statement;
ELSE ! no semicolon before ELSE
stmt2;