1:       $ SET SOURCEFORMAT"FREE"
2: IDENTIFICATION DIVISION.
3: PROGRAM-ID.  PerformFormat4.
4: AUTHOR.  Michael Coughlan.
5: * An example program using the PERFORM..VARYING format.
6: * Pay particular attention to the values produced by the
7: * WITH TEST BEFORE and WITH TEST AFTER loops.
8: * Note that the PERFORM within a PERFORM produces the same
9: * results as the PERFORM..VARYING..AFTER
10:
11:
12: DATA DIVISION.
13: WORKING-STORAGE SECTION.
14: 01  LoopCount          PIC 9  VALUE ZEROS.
15: 01  LoopCount2         PIC S9 VALUE ZEROS.
16:
17: PROCEDURE DIVISION.
18: Begin.
19:     DISPLAY "Start WHILE Iteration of LoopBody"
20:     PERFORM LoopBody WITH TEST BEFORE
21:         VARYING LoopCount FROM 1 BY 2
22:         UNTIL LoopCount GREATER THAN 5.
23:     DISPLAY "Finished WHILE iteration. LoopCount = " LoopCount.
24:
25:     DISPLAY "Start REPEAT Iteration of LoopBody"
26:     PERFORM LoopBody WITH TEST AFTER
27:         VARYING LoopCount FROM 1 BY 2
28:         UNTIL LoopCount GREATER THAN 5.
29:     DISPLAY "Finished REPEAT iteration. LoopCount = " LoopCount.
30:
31:     DISPLAY "Start inline loops"
32:     PERFORM VARYING LoopCount FROM 1 BY 1
33:                     UNTIL LoopCount GREATER THAN 4
34:        PERFORM VARYING LoopCount2 FROM 5 BY -2
35:                        UNTIL LoopCount2 LESS THAN ZERO
36:           DISPLAY "InLine loop " WITH NO ADVANCING
37:           DISPLAY "LoopCount = " LoopCount " LoopCount2 = " LoopCount2
38:        END-PERFORM
39:     END-PERFORM.
40:     DISPLAY "Finished inline loops".
41:
42:     DISPLAY "Start PERFORM VARYING..AFTER".
43:     PERFORM LoopBody VARYING LoopCount FROM 1 BY 1
44:                        UNTIL LoopCount GREATER THAN 4
45:                  AFTER LoopCount2 FROM 5 BY -2
46:                        UNTIL LoopCount2 LESS THAN ZERO.
47:     DISPLAY "Finished PERFORM VARYING..AFTER".
48:     STOP RUN.
49:
50:
51: LoopBody.
52:     DISPLAY "LoopBody " WITH NO ADVANCING
53:     DISPLAY "LoopCount = " LoopCount " LoopCount2 = " LoopCount2.

As of Mon Jul 13 04:53:35 EDT 2015