Rational Developer for System z
Enterprise COBOL for z/OS, Version 4.1, Language Reference


Combined conditions

Two or more conditions can be logically connected to form a combined condition.

Read syntax diagramSkip visual syntax diagram
Format

                .----------------------.   
                V                      |   
>>-condition-1----+-AND-+--condition-2-+-----------------------><
                  '-OR--'                  

The condition to be combined can be any of the following:

Table 1. Combined conditionspermissible element sequences
Combined condition element Left most When not leftmost, can be immediately preceded by: Right most When not rightmost, can be immediately followed by:
simple- condition Yes

OR
NOT
AND
(

Yes

OR
AND
)

OR
AND

No

simple-condition
)

No

simple-condition
NOT
(

NOT Yes

OR
AND
(

No

simple-condition
(

( Yes

OR
NOT
AND
(

No

simple-condition
NOT
(

) No

simple-condition
)

Yes

OR
AND
)

Parentheses are never needed when either ANDs or ORs (but not both) are used exclusively in one combined condition. However, parentheses might be needed to modify the implicit precedence rules to maintain the correct logical relation of operators and operands.

There must be a one-to-one correspondence between left and right parentheses, with each left parenthesis to the left of its corresponding right parenthesis.

The following table illustrates the relationships between logical operators and conditions C1 and C2.

Table 2. Logical operators and evaluation results of combined conditions

Value
for C1

Value
for C2

C1
AND
C2

C1 OR
C2

NOT
(C1
AND
C2)

NOT
C1
AND
C2

NOT
(C1
OR
C2)

NOT C1
OR C2

True True True True False False False True
False True False True True True False True
True False False True True False False False
False False False False True False True True

Order of evaluation of conditions

Parentheses, both explicit and implicit, define the level of inclusiveness within a complex condition. Two or more conditions connected by only the logical operators AND or OR at the same level of inclusiveness establish a hierarchical level within a complex condition. Therefore an entire complex condition is a nested structure of hierarchical levels, with the entire complex condition being the most inclusive hierarchical level.

Within this context, the evaluation of the conditions within an entire complex condition begins at the left of the condition. The constituent connected conditions within a hierarchical level are evaluated in order from left to right, and evaluation of that hierarchical level terminates as soon as a truth value for it is determined, regardless of whether all the constituent connected conditions within that hierarchical level have been evaluated.

Values are established for arithmetic expressions and functions if and when the conditions that contain them are evaluated. Similarly, negated conditions are evaluated if and when it is necessary to evaluate the complex condition that they represent. For example:

NOT A IS GREATER THAN B OR A + B IS EQUAL TO C AND D IS POSITIVE

is evaluated as if parenthesized as follows:

(NOT (A IS GREATER THAN B)) OR
(((A + B) IS EQUAL TO C) AND (D IS POSITIVE))

Order of evaluation:

  1. (NOT (A IS GREATER THAN B)) is evaluated, giving some intermediate truth value, t1. If t1 is true, the combined condition is true, and no further evaluation takes place. If t1 is false, evaluation continues as follows.
  2. (A + B) is evaluated, giving some intermediate result, x.
  3. (x IS EQUAL TO C) is evaluated, giving some intermediate truth value, t2. If t2 is false, the combined condition is false, and no further evaluation takes place. If t2 is true, the evaluation continues as follows.
  4. (D IS POSITIVE) is evaluated, giving some intermediate truth value, t3. If t3 is false, the combined condition is false. If t3 is true, the combined condition is true.

Terms of use | Feedback

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