pTAL Conversion Guide

Hardware Indicators
pTAL Conversion Guide527302-002
20-24
Nesting Condition Code Tests
Nesting Condition Code Tests
You can test for more than one value of the condition code by nesting IF statements,
as in the following example:
Rules for nested IF statements:
$CARRY and $OVERFLOW cannot appear in the conditional expression of any IF
statement in a nest of IF statements:
i := i + 1;
IF > THEN
IF $CARRY THEN ... ! ERROR: Cannot test $CARRY in
! nest of IF statements
i := i + 1;
IF $CARRY THEN ! ERROR: Cannot test $CARRY in
IF > THEN ... ! nest of IF statements
Except as noted in the next point, 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 a NOT operator. The conditional expression cannot include any other
operator or operand. The following example is valid in pTAL:
i := i + 1;
IF <= THEN
IF NOT = THEN... ! OK
The conditional expression of the innermost IF statement can be arbitrarily
complex; the condition code, however, must be the first operand in the expression,
as in the following example:
i := j + 1;
IF >= THEN
IF = AND (j + 4) / 5 * 5 > 0 THEN ... ! OK
Example 20-11. Nesting Condition Code Tests
i := i + 1;
IF < THEN ...
ELSE IF = THEN ...
ELSE ... ! Must be >
Example 20-12. Testing Condition Code for Multiple Values
INT PROC p;
BEGIN
CALL READX( ... );
IF < THEN RETURN -1
ELSE IF > THEN RETURN 1
ELSE RETURN 0;
END;