Module 6: Procedure Division
CONDITIONAL verb : IF
- Verb IF can be used to compare two values and if result is true, statement following condition will be executed
- Complete structure of IF/THEN/ELSE/END-IF will be explained in later module <link to IF ELSE>
- Basic syntax for usage of IF verb:-
IF condition-1 statement-1Where, connidtion-1 can be ‘=’, ‘<’, ’>’, ‘>=’, ‘<=’, ‘<>’. statement-1 can be any COBOL statement
- Example 1:-
In PROCEDURE DIVISION,IF A > 5 MOVE A TO MAX.Suppose, value of A is 15, then value of A i.e. 15 will be moved to MAX. If value of A is 3, MOVE statement will not be executed
- Example 2:-
In PROCEDURE DIVISION,IF A NOT = 5 MOVE 5 TO A DISPLAY ‘VALUE MOVED’.In above example, if value of A is not equal to 5 then, 5 will be moved to A and SYSOUT will be displayed as ‘VALUE MOVED’. In case, if value of A is already 5, both MOVE and DISPLAY will be skipped as both these are coded before period.