Cobol Decision

When the criteria of a tested condition are met, the condition is considered to be true.   When the criteria of a tested condition are not met, the condition is considered to be false.

The DISPLAY statement at line 003000 is executed only when the condition being tested by the IF at line 002900 (YES-OR-NO IS EQUAL "Y") is true.

When the IF at line 002900 is not true (any character but Y is entered), line 003000 is skipped.   The DISPLAY statement at line 003300 is executed only when the condition being tested by the IF at line 003200 (YES-OR-NO IS EQUAL "N") is true.

When the IF at line 003200 is not true (any character but N is entered), line 003300 is skipped.

When a condition tested by an IF statement is not true, any statements controlled by the IF are not executed.

This is the output of yesno01.cbl if you enter a Y:

OUTPUT:

Is the answer Yes or No? (Y/N)
Y
You answered Yes.

C>
C>
Sample Code
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. YESNO01.
000300*--------------------------------------------------
000400* This program asks for a Y or N answer, and then
000500* displays whether the user chose yes or no.
000600*--------------------------------------------------
000700 ENVIRONMENT DIVISION.
000800 DATA DIVISION.
000900 WORKING-STORAGE SECTION.
001000
001100 01  YES-OR-NO      PIC X.
001200
001300 PROCEDURE DIVISION.
001400 PROGRAM-BEGIN.
001500
001600     PERFORM GET-THE-ANSWER.
001700
001800     PERFORM DISPLAY-THE-ANSWER.
001900
002000 PROGRAM-DONE.
002100     STOP RUN.
002200
002300 GET-THE-ANSWER.
002400
002500     DISPLAY "Is the answer Yes or No? (Y/N)".
002600     ACCEPT YES-OR-NO.
002700
002800 DISPLAY-THE-ANSWER.
002900     IF YES-OR-NO IS EQUAL "Y"
003000         DISPLAY "You answered Yes.".
003100
003200     IF YES-OR-NO IS EQUAL "N"
003300         DISPLAY "You answered No.".
003400