99 Bottles of Beer

I guess I should explain this, and what it has to do with programming. There is a popular drinking song in the USA that goes basically like this:

99 bottles of beer on the wall,
99 bottles of beer
Take one down and pass it around,
98 bottles of beer on the wall.

and so on. Some time in 1994, someone posted the full text to a humor mailing list, and I mean the full text, all 99 stanzas down to the last bottle. In real life, I guess, most people have passed out by then. Someone complained that this was a blatant waste of bandwidth, when it could have been done with only six lines of BASIC:

10 REM BASIC Version of 99 Bottles of beer
20 FOR X=100 TO 1 STEP -1
30 PRINT X;"Bottle(s) of beer on the wall,";X;"bottle(s) of beer"
40 PRINT "Take one down and pass it around,"
50 PRINT X-1;"bottle(s) of beer on the wall"
60 NEXT

This in turn angered the C++ programmers, who did not like the promotion of such a vastly inferior and dangerous language. So Tim Robinson wrote a version in C++:

// C++ version of 99 Bottles of beer
// programmer: Tim Robinson timtroyr@ionet.net
#include <fstream.h>

int main()
    {
    int bottles = 99;
    while ( bottles > 0 )
        {
        cout << bottles << " bottle(s) of beer on the wall," << endl;
        cout << bottles << " bottle(s) of beer." << endl;
        cout << "Take one down, pass it around," << endl;
        cout << --bottles << " bottle(s) of beer on the wall." << endl;
        }
    return 0;
    }

and this opened a floodgate. Tim Robinson started a list that grew from twenty to 227 versions. In 1998, Oliver Schade asked for permission to mirror Tim's pages in his Best of the Internet collection. Three years later, Tim's pages vanished, and Oliver Schade took over. In February 2003, you could compile 99 Bottles of Beer in 387 languages or at least variants. In July 2004, this number had risen to 621. There is still a mirror of the original site, too.

While the whole thing started as a joke and is still run as a joke, it is actually a very useful exercise if you start to learn programming, better than the beginner's examples you are usually treated to.

Last modified 2010-12-28