cobolgnucobol

Is there a way I could make a perform not end (like an infinite while loop)?


Is there anyway to do this? I want the perform to exit only when a exit statement is executed. If not I want it to keep looping.


Solution

  • I like using "PERFORM FOREVER" because it clearly identifies the code as an infinite loop. "PERFORM UNTIL EXIT" works too. Below is some example code that uses an infinite loop and an "EXIT PERFORM" statement to print the numbers 1 to 10. This code works with GNUCobol 2.0.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. INFINITE-LOOP.
    
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
    
       DATA DIVISION.
       FILE SECTION.
    
       WORKING-STORAGE SECTION.
       01  COUNTER                          PIC 99 VALUE ZERO.
    
       PROCEDURE DIVISION.
    
      * USE EITHER OF THE TWO FOLLOWING LINES
      * WHICHEVER YOU FIND MORE MEANINGFUL
      *    PERFORM UNTIL EXIT
           PERFORM FOREVER
               ADD 1 TO COUNTER
               DISPLAY COUNTER
               IF COUNTER > 9
                   EXIT PERFORM
               END-IF
           END-PERFORM
           STOP RUN
           .