Search code examples
recursioncobolmainframe

In COBOL, is it possible to recursively call a paragraph?


In COBOL for an IBM Mainframe is it possible to call a paragraph recursively?

200-PARAGRAPH SECTION.

    IF WS-COUNTER < 10
       ADD 1 TO WS-COUNTER
       PERFORM 200-PARAGRAPH
    ELSE
       DISPLAY 'I'M DONE'
    END-IF.

 200-EXIT.
    EXIT.

Solution

  • Check the current COBOL Language Reference, but AFAIR a para cannot PERFORM itself. The wording is something like you will get unpredictable results, as recursion is not supported.

    If you need to wind over the same code perhaps refactoring to use PERFORM UNTIL is what you need?