pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
The following rules apply to nested IF statements:
• Neither $OVERFLOW nor $CARRY can appear in the conditional expression of any IF statement
in a nest of IF statements.
I := i + 1;
IF > THEN
IF $OVERFLOW THEN ... ! ERROR: cannot test $OVERFLOW in
! nest of IF statements
i := i + 1;
IF $CARRY THEN ! ERROR: cannot test $CARRY in
IF > THEN ... ! nest of IF statements
You cannot test $OVERFLOW or $CARRY to determine if an overflow or carry occurred while
evaluating an IF statement’s conditional expression.
IF i + 1 < 100 THEN
BEGIN
IF $CARRY THEN ... ! ERROR: invalid to test $CARRY here
END
You can test $OVERFLOW or $CARRY by evaluating, in a separate assignment statement,
the expression in which overflow or carry could occur, then test $OVERFLOW or $CARRY.
INT temp;
temp := i + 1; ! Carry could occur here
IF NOT $CARRY THEN ! OK to test $CARRY here
BEGIN
IF temp < 100 THEN ...
END
ELSE ... ! Handle $CARRY condition
• Except as noted in the following item, the conditional expression in each IF statement in a nest
of IF statements can test only the value of the condition code, optionally preceded by the NOT
operator. The conditional expression cannot include any other operator or operand.
I := i + 1;
IF <= THEN
IF NOT = THEN ... ! OK
• The conditional expression of the innermost IF statement can be a complex expression, but
the condition code must be the first operand in the expression.
I := j + 1;
IF >= THEN
IF = AND (j + 4) / 5 * 5 > 0 THEN ... ! OK
• If the root operator in the conditional expression of an IF statement is a relational operator,
the first statement in the THEN or ELSE clause of the IF statement can be an IF statement that
tests the condition code set by the root operator of the encompassing IF statement.
IF (i + 10) <= (m - 2) THEN ! Root operator (<=) is
BEGIN ! relational operator
IF < THEN ! OK: test if condition was
... ! "less than"
ELSE
END;
IF (i < -1) OR (i > 1) THEN
BEGIN
IF < THEN ! ERROR: root operator of IF
... ! statement is Boolean,
END; ! not relational
• If an outer IF statement’s conditional expression uses a signed operator (= or <>) to compare
two 16-bit addresses, an inner IF statement’s THEN or ELSE clause cannot test the condition
code established by the outer IF statement’s conditional expression.
Nesting Condition Code Tests 243