pTAL Guidelines for TAL Programmers

Coding Guidelines
pTAL Guidelines for TAL Programmers527256-002
2-45
Hardware Indicators: Test Only the Condition Code
in a Nest of IF Statements
Hardware Indicators: Test Only the Condition Code in a Nest of
IF Statements
Guideline: Use nested IF statements to test the value only of the condition code, not
of $OVERFLOW or $CARRY.
In pTAL, you cannot test $OVERFLOW or $CARRY in an IF statement that participates
in a nest of IF statements—including the innermost and outermost IF statements.
Example 2-54 on page 2-45 and Example 2-55 on page 2-45 are invalid in pTAL.
If you need to test $OVERFLOW or $CARRY and also the condition code, test
$CARRY in a separate IF statement, as in Example 2-56 on page 2-46 and
Example 2-57 on page 2-46.
Example 2-53. Testing Condition Code in ELSE Part of Nested IF Statement
i := i + 1;
IF > THEN
BEGIN
...
END
ELSE
IF < AND i <> 10 THEN ! OK: conditional expression in
BEGIN ! innermost IF contains condition code
... ! test first, followed by another test
END;
Example 2-54. Invalid $OVERFLOW Test (pTAL)
?NOOVERFLOW_TRAPS ! Disable overflow traps
i := i + 1;
IF NOT $OVERFLOW THEN ! Overflow test on this line renders test
BEGIN ! for <> invalid on this line
IF <> THEN ...
END;
?OVERFLOW_TRAPS ! Enable overflow traps
Example 2-55. Invalid $CARRY Test (pTAL)
i := i '+' 1;
IF NOT <> THEN ! OK
IF $CARRY THEN ... ! ERROR: invalid because test is nested
! within another IF statement