Rational Developer for System z
Enterprise PL/I for z/OS, Version 3.8, Language Reference Manual

IF statement

Examples
Short-circuit evaluation

The IF statement evaluates an expression and controls the flow of execution according to the result of that evaluation. The IF statement thus provides a conditional branch.

Note:
Condition prefixes are invalid on ELSE statements.
Read syntax diagramSkip visual syntax diagram>>-IF--expression--THEN--unit1--+-------------+----------------><
                                '-ELSE--unit2-'
 
expression
The expression must have the attributes BIT(1) NONVARYING unless RULES(LAXIF) is used.

When expressions involve the use of the & and/or | operators, they are evaluated as described in Combinations of operations.

unit
Either a valid single statement, a group, or a begin-block. All single statements are considered valid and executable except DECLARE, DEFAULT, END, ENTRY FORMAT, PROCEDURE, or a %statement. If a nonexecutable statement is used, the result can be unpredictable. Each unit can contain statements that specify a transfer of control (for example, GO TO). Hence, the normal sequence of the IF statement can be overridden.

Each unit can be labeled and can have condition prefixes.

IF is a compound statement. The semicolon terminating the last unit also terminates the IF statement.

If any bit in the string expression has the value '1'B, unit1 is executed and unit2, if present, is ignored. If all bits are '0'B, or the string is null, unit1 is ignored and unit2, if present, is executed.

IF statements can be nested. That is, either unit can itself be an IF statement, or both can be. Since each ELSE is always associated with the innermost unmatched IF in the same block or do-group, an ELSE with a null statement might be required to specify a desired sequence of control. For example, if B and C are constants, the following example:

if A = B then

·
·
·
else if A = C then
·
·
·
else
·
·
·

is equivalent to and would be better coded as:

select( A );
when ( B )

·
·
·
when ( C )
·
·
·

·
·
·
end;

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)