Category: Examples

  • Loop (Perform Until)

    Explanation: PERFORM UNTIL → loop continues until condition is met. COUNTER → starts at 1, increments until 5. Output: ini COUNTER = 1COUNTER = 2COUNTER = 3COUNTER = 4COUNTER = 5

  • Simple IF ELSE

    IDENTIFICATION DIVISION.PROGRAM-ID. CHECK-NUMBER. Explanation: IF NUM > 100 → checks condition. DISPLAY → shows different messages based on condition.

  • User Input and Display

    Explanation: PIC A(20) → allows up to 20 alphabetic characters. ACCEPT USER-NAME → takes input from user. DISPLAY → prints greeting with input.

  • Add Two Numbers

    Explanation: WORKING-STORAGE SECTION → used to declare variables. 01 NUM1 PIC 9(3) → variable with 3 digits (e.g., 025). ADD NUM1 TO NUM2 GIVING SUM → performs addition. DISPLAY → shows result. Output: THE SUM IS: 55

  • Hello World Program

    Explanation: IDENTIFICATION DIVISION → declares the program name. PROGRAM-ID → the name of the program (HELLO-WORLD). PROCEDURE DIVISION → instructions. DISPLAY → prints output on screen. STOP RUN → ends the program.