TAL Programmer's Guide

IF Expression
Using Special Expressions
13–4 096254 Tandem Computers Incorporated
IF Expression The IF expression conditionally selects one of two expressions, usually for assignment
to a variable. To use an IF expression, specify:
IF condition
Specifies a condition that, if true, causes the result of the THEN expression to
become the result of the overall IF expression. If the condition is false, the result of
the ELSE expression becomes the result of the overall IF expression. The condition is
either:
A conditional expression
An INT arithmetic expression. If the result of this expression is not 0, the
condition is true. If the result is a 0, the condition is false.
THEN expression
Specifies an expression to evaluate if the condition is true. The expression is either:
An INT arithmetic expression
A conditional expression (excluding a relational operator with no operands),
the result of which has data type INT.
ELSE expression (optional)
Specifies the expression to evaluate if the condition is false. The expression is either:
An INT arithmetic expression
A conditional expression (excluding a relational operator with no operands),
the result of which has data type INT
For example, you can assign either of two arithmetic expressions to VAR depending on
the condition LENGTH > 0:
var := IF length > 0 THEN 10 ELSE 20;
You can include an IF expression, enclosed in parentheses, inside another expression:
var := index +
(IF index > limit THEN var * 2 ELSE var * 3);
You can nest an IF expression within another IF expression:
var := IF length < 0 THEN -1
ELSE IF length = 0 THEN 0
ELSE 1;
The IF expression resembles the IF statement except that:
The THEN and ELSE clauses are both required in the IF expression.
The THEN and ELSE clauses contain expressions, not statements.