PERFORM THROUGH|THRU


The PERFORM statement is used to execute a specific paragraph or a range of paragraphs. PERFORM...THROUGH (or PERFORM...THRU) specifies a block of consecutive paragraphs to be executed. PERFORM THROUGH is outline PERFORM.

Syntax -

PERFORM paragraph-1 THROUGH paragraph-2

OR

PERFORM paragraph-1 THRU paragraph-2

Parameters -

  • paragraph-1 - The starting paragraph to be executed.
  • paragraph-2 - The ending paragraph. After executing this paragraph, control returns to the statement following the PERFORM.

Practical Example -


Scenario - Executing paragraphs using PERFORM...THRU.

Code -

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

       PROCEDURE DIVISION.
           PERFORM 1000-DISPLAY1
              THRU 3000-DISPLAY3.
           STOP RUN.

       1000-DISPLAY1.
           DISPLAY "Paragraph1".
       2000-DISPLAY2.
           DISPLAY "Paragraph2".
       3000-DISPLAY3.
           DISPLAY "Paragraph3".
       4000-DISPLAY3.
           DISPLAY "Paragraph4".

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, we have four paragraphs coded. PERFORM statement only executes 1000-DISPLAY1 THRU 3000-DISPLAY3. After 3000-DISPLAY2 execution, control returns back to PROCEDURE DIVISION.