codegurukool.com · Free coding tutorials & online compiler

Home › COBOL Tutorial › COBOL IF...ELSE

COBOL IF...ELSE

Make decisions.

IF condition ... ELSE ... END-IF. Conditions use =, >, <, >=, <=, NOT, AND and OR. Always close with END-IF so nested blocks are clear.

Example code

       IDENTIFICATION DIVISION.
       PROGRAM-ID. IFS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 SCORE PIC 999 VALUE 72.
       PROCEDURE DIVISION.
           IF SCORE >= 90
               DISPLAY "A"
           ELSE
               IF SCORE >= 70
                   DISPLAY "B"
               ELSE
                   DISPLAY "C"
               END-IF
           END-IF.
           IF SCORE >= 60 AND SCORE <= 100
               DISPLAY "pass"
           END-IF.
           STOP RUN.

Run this code in the online editor

← COBOL edited picturesCOBOL class tests and condition names →