Vadim Zaytsev aka @grammarware

BabyCobol: 99 Bottles of Beer

The task is to print the full lyrics of a popular song. The solution can also be found on Rosetta Code.

       IDENTIFICATION DIVISION.
       PROGRAM-ID.  99 BOTTLES.
       DATA DIVISION.
       01 DATA PICTURE IS 999.
       PROCEDURE DIVISION.
           LOOP VARYING DATA FROM 99 BY 0
               PERFORM COUNT-BOTTLES THROUGH END
               DISPLAY DATA "bottles of beer"
               DISPLAY "Take one down, pass it around"
               SUBTRACT 1 FROM DATA
               IF DATA = 1
               THEN ALTER COUNT-BOTTLES TO PROCEED TO SINGLE-BOTTLE
               END
               PERFORM COUNT-BOTTLES THROUGH END
               DISPLAY ""
           END.
       NO-BOTTLES-LEFT.
           DISPLAY "No bottles of beer on the wall"
           DISPLAY ""
           DISPLAY "Go to the store and buy some more"
           DISPLAY "99 bottles of beer on the wall".
           STOP.
       COUNT-BOTTLES.
           GO TO MANY-BOTTLES.
       SINGLE-BOTTLE.
           DISPLAY DATA "bottle of beer on the wall".
           GO TO NO-BOTTLES-LEFT.
       MANY-BOTTLES.
           DISPLAY DATA "bottles of beer on the wall".
       END.
           NEXT SENTENCE.

BabyCobol is a project by Dr. Vadim Zaytsev a.k.a. @grammarware. Page last updated in March 2024.
XHTML 1.1 CSS 3