cobol

PERFORM statement

Remarks#

The PERFORM statement transfers control to one or more procedures and returns control implicitly when the sequence completes. PERFORM can also be used for inline loops withing the scope of the PERFORM.

The VARYING phrase allows for nesting with one or more AFTER clauses, and the conditional test can be BEFORE (default) or AFTER each loop.

The THRU clause of a procedural perform assumes sequential top down control flow from procedure-1 through the end of procedure-2. THRU is a contentious issue, and many programmers prefer PERFORM by SECTION rather than using THRU paragraphs. Some shops may mandate PERFORM THRU with an explicit exit point paragraph, others may ban the use of THRU finding it more difficult to debug.

Procedural perform:

PERFORM procedure syntax diagram

Inline perform:

Inline PERFORM syntax diagram

Where varying-phrase is:

varying-phrase

Inline PERFORM VARYING

PERFORM VARYING TALLY FROM 1 BY 1 UNTIL TALLY > 5
    DISPLAY TALLY
END-PERFORM

Procedural PERFORM

PERFORM some-paragraph

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow