Example of if- else statement, COBOL Programming

Example of If- else statement

Illustration:

IF QUANTITY IS NUMERIC AND QUANTITY IS POSITIVE

MOVE ZERO TO ERROR-CODE. COMPUTE SALES VALUE=QUANTITY*RATE

ELSE MOVE 1 TO ERROR -CODE

MOVE ZERO TO SALES-VALUE

The particular condition tests whether or not the present value of the data name QUANTITY is numeric as well as positive. If the condition is true then ERROR-CODE is set to zero and SALES-VALUE is computed by multiplying the QUANTITY by RATE. On the other hand, when the condition is FALSE, then ERROR CODE is set to 1 and SALES-VALUE is set to zero. In either situation the control goes implicitly to the next statement after this IF sentence. The above sentence is equal to the following flowchart.