pTAL Conversion Guide

Hardware Indicators
pTAL Conversion Guide527302-002
20-25
Testing Condition Codes Set in Conditional
Expressions
Example 20-13 on page 20-25 is functionally equivalent to Example 20-12 on
page 20-24 but is valid only in TAL.
Testing Condition Codes Set in Conditional Expressions
If the root operator—that is, the last operator executed—in the conditional expression
of an IF statement is a relational operator (<, =, >, <=, <>, >=, '<', '=', '>', '<=', '<>', or
'>=') 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, as in Example 20-15 on page 20-25.
Example 20-13. Testing Condition Code for Multiple Values (TAL only)
INT PROC p;
BEGIN
CALL READ( ... );
IF < THEN RETURN -1; ! OK
IF > THEN RETURN 1; ! ERROR: Condition code must be tested
RETURN 0; ! immediately after statement
END; ! that sets it
Example 20-14. Testing Condition Code for Multiple Values (TAL only)
CALL READX( ... );
IF $CARRY THEN RETURN -1 ! ERROR: $CARRY is invalid in
ELSE IF > THEN RETURN 1 ! nest of IF statements
ELSE RETURN 0;
Example 20-15. Testing Condition Codes Set in Conditional Expressions
IF (i + 10) <= (m - 2) THEN ! Root operator (<=) is a
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