TAL Programmer's Guide

IF Statement
Controlling Program Flow
12–2 096254 Tandem Computers Incorporated
IF Statement The IF statement conditionally selects one of two statements. The IF statement tests
the condition before selecting a statement. If the condition is true, the THEN clause
executes. If the condition is false, the ELSE clause executes, if present.
To specify an IF statement, include:
IF condition
Specifies a condition that, if true, causes the THEN clause to execute. If false, the
condition causes the ELSE clause to execute. If no ELSE clause is present, the
statement following the IF statement executes. The condition can be either:
A conditional expression
An INT arithmetic expression. If the result of the arithmetic expression is not
0, the condition is true. If the result is 0, the condition is false.
THEN statement
Specifies a statement to execute if the condition is true. If you omit the statement
in the THEN clause, no action occurs for the THEN clause. The statement can be
any TAL statement.
ELSE statement (optional)
Specifies a statement to execute if the condition is false. If the condition is false and
no ELSE clause is present, the statement following the IF statement executes. The
statement can be any TAL statement.
For example, the following IF statement calls an error handler if VAR_ITEM contains a
nonzero value:
INT var_item;
!Some code here
IF var_item <> 0 THEN
CALL error_handler;
The following example is equivalent to the preceding example:
IF var_item THEN
CALL error_handler;
The following IF statement compares two arrays. If the arrays are equal, the IF
statement assigns a 1 to ITEM_OK. If they are not equal, it assigns 0 to ITEM_OK:
INT new_array[0:9];
INT old_array[0:9];
INT item_ok;
!Some code here
IF new_array = old_array FOR 10 WORDS THEN
item_ok := 1 !No semicolon when followed by ELSE
ELSE
item_ok := 0;