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 TIMESThe count can be a field. A count of zero runs the paragraph no times:
ACCEPT COPIES
PERFORM PRINT-LABEL COPIES TIMESA 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
EasyThe 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
3Paragraphs and Loops
Paragraphs and PERFORMPERFORM TIMESPERFORM UNTILPERFORM VARYINGInline PERFORMGO TO and Why Not