Example

PERFORM procedure-name-1 THROUGH procedure-name-2
      VARYING identifier-2 FROM identifier-3
            BY identifier-4 UNTIL condition-1
         AFTER identifier-5 FROM identifier-6
            BY identifier-7 UNTIL condition-2
  1. identifier-2 and identifier-5 are set to their initial values, identifier-3 and identifier-6, respectively.
  2. condition-1 is evaluated as follows:
    1. If it is false, steps 3 through 7 are executed.
    2. If it is true, control passes directly to the statement following the PERFORM statement.
  3. condition-2 is evaluated as follows:
    1. If it is false, steps 4 through 6 are executed.
    2. If it is true, identifier-2 is augmented by identifier-4, identifier-5 is set to the current value of identifier-6, and step 2 is repeated.
  4. procedure-name-1 and everything up to and including procedure-name-2 (if specified) are executed once.
  5. identifier-5 is augmented by identifier-7.
  6. Steps 3 through 5 are repeated until condition-2 is true.
  7. Steps 2 through 6 are repeated until condition-1 is true.
At the end of PERFORM statement execution:

Figure 1 illustrates the logic of the PERFORM statement when two identifiers are varied with TEST BEFORE. Figure 2 illustrates the logic of the PERFORM statement when two identifiers are varied with TEST AFTER.

Figure 1. Varying Two Identifiers—with TEST BEFORE
This figure illustrates the logic of the PERFORM statement when two identifiers are varied with TEST BEFORE

The previous figure assumes that identifier-5 and identifier-2 are not related. If one is dependent on the other (through subscripting, for example), the results may be predictable but generally undesirable.

Figure 2. Varying Two Identifiers—with TEST AFTER
This figure illustrates the logic of the PERFORM statement when two identifiers are varied with TEST AFTER