Simple IF
Simple IF Example
Scenario - Validating gender using simple IF.
Code -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. SIMPIF.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
05 WS-GENDER PIC X(01) VALUE "M".
PROCEDURE DIVISION.
IF WS-GENDER EQUAL "M"
DISPLAY "Person is Male"
END-IF.
STOP RUN.
Output -
Person is Male
Explaining Example -
In the above example:
- IF condition validates WS-GENDER EQUAL "M" and based on its truth value, the control flow gets decided.
- The condition is true, so it displays "Person is Male".