PERFORM TIMES in COBOL
The simplest loop: ring the ship's bell a counted number of times.
IDENTIFICATION DIVISION.
PROGRAM-ID. PERFORM-TIMES.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 BELL-COUNT PIC 9 VALUE 6.
PROCEDURE DIVISION.
*> An inline PERFORM repeats its block a fixed number of times.
PERFORM BELL-COUNT TIMES
DISPLAY "ding"
END-PERFORM
DISPLAY "Six bells: three hours into the watch"
STOP RUN.
How it works
PERFORM BELL-COUNT TIMESrepeats the block once per bell.- The body is a single
DISPLAY;END-PERFORMcloses the loop. - Six bells on the dot: the count lives in data, not in the code.
Keywords and builtins used here
DATADISPLAYDIVISIONIDENTIFICATIONPERFORMPROCEDURESECTIONSTOP
The run, in numbers
- Lines
- 12
- Characters to type
- 315
- Tokens
- 34
- Three-star pace
- 45 tpm
At the three-star pace of 45 tokens a minute, this run takes about 45 seconds.
Step 1 of 3 in Loops, step 16 of 27 in Language basics.