COBOL Looping Statements

Iterative programming involves making a set of statements run in a repetitive, iterative, or looping manner. In iterative programming, the statements execute repeatedly until the coded condition is true. The PERFORM statement is part of iterative programming in COBOL and is also called a looping statement.

PERFORM Statement

PERFORM statement executes the statement block repeatedly. The repetitive execution can be conditional or unconditional. If any condition is coded with it, the statements block gets executed until the coded condition is true.

END-PERFORM -

END-PERFORM is used to end the scope of the in-line PERFORM statement. It is optional if the statements under PERFORM end with a period. The period is considered as a logical end of the PERFORM statement.

Note! PERFORM statement is explained in the next chapter.

PERFORM Types -

PERFORM statement is mainly two types at high level based on how it is coded to perform the task –

  • Inline PERFORM
  • Outline PERFORM

The below table describes the differences between inline an outline PERFORM statements –

Inline PERFORMOutline PERFORM
PERFORM 
   statements-block
END-PERFORM.
PERFORM paragraph-name|section-name.
The PERFORM statement executes the statements block that is coded inline (between PERFORM and END-PERFORM) The PERFORM statement executes statements block that are coded outline (in a separate paragraph or section outside of PERFORM).
This requires no seperate paragraph or section. It requires a separate paragraph or seection that needs to be coded with statements block.
Not required to transfer the control to paragraph or section. Control transfers to the paragraphs or sections
Scope terminator END-PERFORM is mandatory Scope terminator END-PERFORM is not required
Note!
  • A PERFORM statement should not call itself and it can produce unpredictable results.
  • The inline and outline PERFORM formats can't be coded together.

Different PERFORM Formats -

PERFORM statement has five different formats and those are -