# COBOL - Combined Condition

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

Syntax:

 ```IF [CONDITION] AND/OR [CONDITION] COBOL Statements END-IF.```

The condition to be combined can be any of the following:
• A simple-condition
• A negated simple-condition
• A combined condition

Example 1:

 `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))`

It is important to understand the 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.

Example 2:

Let's see another example for combined condtion.

 ```IDENTIFICATION DIVISION. PROGRAM-ID. CBLCOMBN. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-NUM1 PIC 9(2) VALUE 20. 01 WS-NUM2 PIC 9(2) VALUE 25. 01 WS-NUM3 PIC 9(2) VALUE 20. PROCEDURE DIVISION. A000-FIRST-PARA. IF WS-NUM1 IS LESS THAN WS-NUM2 AND WS-NUM1 = WS-NUM3 THEN DISPLAY 'BOTH CONDITION OK' ELSE DISPLAY 'ANY ONE OR BOTH CONDITION FAILED' END-IF. STOP RUN. ```

When you compile and execute the above program, it produces the following result −

Output:

 ```BOTH CONDITION OK ```

If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!