Menu
CoddyTech

PERFORM TIMES

Part of the Decisions and Loops section of Coddy's COBOL Programming journey. Lesson 12 of 20.

PERFORM ... TIMES runs a paragraph a fixed number of times, then goes on with the next statement:

PERFORM PRINT-STAR 3 TIMES

The count can be a field. A count of zero runs the paragraph no times:

ACCEPT COPIES
PERFORM PRINT-LABEL COPIES TIMES

A TIMES loop has no counter you can read. When each pass does the same work, such as taking off a monthly fee, that is all it needs:

TAKE-FEE.
    SUBTRACT 25 FROM BALANCE.
challenge icon

Challenge

Easy

The program reads N. Print N lines of * with PRINT-STAR, then Done. For 2 the output is two lines of * and then Done.

Example input, one line per ACCEPT: 2.

Try it yourself

       IDENTIFICATION DIVISION.
       PROGRAM-ID. STARS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 N PIC 99.
       PROCEDURE DIVISION.
       MAIN-PARA.
           ACCEPT N.
           *> Perform PRINT-STAR N times
           DISPLAY "Done".
           STOP RUN.
       PRINT-STAR.
           DISPLAY "*".

All lessons in Decisions and Loops