Inline Perform Until Example


Scenario - Displaying loop iterations using inline PERFORM...UNTIL.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. PERFIUNT.
       AUTHOR. MTH.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-I         PIC 9(01) VALUE 1.

       PROCEDURE DIVISION.

           DISPLAY "Before PERFORM UNTIL".
           PERFORM UNTIL WS-I > 3 
                   DISPLAY "WS-I: " WS-I
                   COMPUTE WS-I = WS-I + 1
           END-PERFORM.
           DISPLAY "After PERFORM UNTIL".

           STOP RUN.

Output -

Before PERFORM UNTIL
WS-I: 1             
WS-I: 2             
WS-I: 3             
After PERFORM UNTIL 

Explaining Example -

In the above example:

  • It is a inline PEFORM UNTIL loop that iterates the loop until WS-I greater than 3.
  • It displays the iteration number each time before incrementing it.