Two or more conditions can be logically connected to form a combined condition.
Format .----------------------. V | >>-condition-1----+-AND-+--condition-2-+----------------------->< '-OR--'
The condition to be combined can be any of the following:
| 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 |
Yes | OR |
OR |
No | simple-condition |
No | simple-condition |
| NOT | Yes | OR |
No | simple-condition |
| ( | Yes | OR |
No | simple-condition |
| ) | No | simple-condition |
Yes | OR |
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.
Value |
Value |
C1 |
C1 OR |
NOT |
NOT |
NOT |
NOT C1 |
|---|---|---|---|---|---|---|---|
| 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 |
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))