Inline Perform Times Example


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

Code -

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

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

       PROCEDURE DIVISION.

	       DISPLAY "Before Inline PERFORM...TIMES".
           PERFORM 6 TIMES
              DISPLAY "Iteration: " WS-I 
              COMPUTE WS-I = WS-I + 1
           END-PERFORM.
	       DISPLAY "After Inline PERFORM...TIMES".

           STOP RUN.

Output -

Before Inline PERFORM...TIMES
Iteration: 1
Iteration: 2
Iteration: 3
Iteration: 4
Iteration: 5
Iteration: 6
After Inline PERFORM...TIMES

Explaining Example -

In the above example:

  • It is a inline PEFORM loop that iterates 6 times, displaying the iteration number each time before incrementing it.