Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language BASIC

Date:05/27/05
Author:M. Eric Carr
URL:n/a
Comments:12
Info:n/a
Score: (3.23 in 120 votes)
 10 REM Basic version of 99 bottles of beer
 20 REM Modified by M. Eric Carr (eric@carrnet.net)
 30 REM from prior version found on this site.
 40 REM (Modified to correct "1 bottle" grammar)
 50 FOR X=99 TO 1 STEP -1
 60 PRINT X;"bottle";
 70 IF X<>1 THEN PRINT "s";
 80 PRINT " of beer on the wall,";X;"bottle";
 90 IF X<>1 THEN PRINT "s";
100 PRINT " of beer"
110 PRINT "Take one down and pass it around,"
120 PRINT X-1;"bottle";
130 IF X<>1 THEN PRINT "s";
140 PRINT " of beer on the wall"
150 NEXT

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
1Anonymous04/20/051

Comments

>>  Roland Wright said on 11/02/05 14:01:04

Roland Wright On some versions of BASIC (I used Microsoft BASIC on the TRS-80) the NEXT statement would have to specify the variable that is being incremented; NEXT X

>>  Bart Barber said on 12/22/05 19:53:08

Bart Barber Actually, shouldn't the last decision on whether to pluralize "bottle" (line 130) be checking X-1 instead of X?

>>  Watts Martin said on 01/10/06 08:50:25

Watts Martin Roland: FYI, TRS-80 BASIC didn't need the variable after the NEXT statement unless there were nested loops.

This particular code looks way too much like something I'd have written for this, too. Argh. Flashbacks. :)

>>  Chris said on 07/30/06 21:15:30

Chris Bart Barber: The variable X has already been reduced in the previous line. 130 IF X<>1 THEN PRINT "s";

>>  M. Eric Carr said on 08/13/06 19:06:07

M. Eric Carr Yep -- that is a bug. Line 130 should read:
130 IF X<>1 THEN PRINT "s";

Sorry 'bout that. Good catch.

...and yes, it would be more universal to write

150 NEXT X

--Eric

>>  Mike said on 11/16/06 23:21:15

Mike Wouldn't this save a few bytes of source file size? LOL

10 REM Basic version of 99 bottles of beer
20 REM Modified by Mike Daugherty
30 REM from prior version found on this site.
40 REM (Modified to add print subroutine)
50 t1$="bottle":t2$=" of beer on the wall,":t3$=" of beer"
60 t4$="Take one down and pass it around,"
70 FOR X=99 TO 1 STEP -1
80 PRINT X;t1$;
90 GOSUB 200
100 PRINT t2$;X;t1$;
110 GOSUB 200
120 PRINT t3$
130 PRINT t4$
140 PRINT X-1;t1$;
150 GOSUB 200
160 PRINT t2$
170 NEXT
180 END

190 REM PLURAL
200 IF X <> 1 THEN PRINT "s";
210 RETURN

>>  petchema said on 11/17/06 11:01:46

petchema Last test should be IF X-1<>1 THEN ..., or IF X<>2 THEN ...
So it doesn't factorize so easily.

Either way, that program doesn't print the reference lyrics.

>>  Doug said on 01/02/07 16:58:22

Doug Need the "No more bottles of beer on the wall, no more bottles of beer,
go to the store, buy some more..."

>>  Medical-Wei said on 03/26/07 11:34:56

Medical-Wei 10 REM This is the much shorter version... The last line doesn't well...
20 FOR X=99 TO 0 STEP -1
30 ProcStr$=X;"bottles of beer"
40 IF X=1 THEN ProcStr$="1 bottle of beer"
50 IF X=0 THEN ProcStr$="No more bottles of beer"
60 IF X<>99 THEN "Take one down and pass it around,";ProcStr$;"on the wall."
70 PRINT ProcStr$;"on the wall,";ProcStr$;"."
80 NEXT X
90 PRINT "Go to the store and buy some more, 99 bottles of beer on the wall."

>>  E said on 04/20/07 13:42:37

E
You assclown, this is rubbish im dissapinted in you sonny jim. Please Note:THIS IS FAKE

>>  Cld said on 11/18/07 22:03:44

Cld Medical-Wei:
Some BASIC doesn't support "long" variable and only supporte one char variable...

>>  Anonymous said on 08/31/08 04:19:16

Anonymous Just came across this site. Decided to Break out my TRS-80 and Write this
10 REM 99 Bottles of Beer
20 CLEAR 1000: X=99:LY$="Bottle":LX$=Bottles":LZ$=" of beer on the Wall.":LV$="Take one Down and pass it around."
30 PRINTX;LX$+LZ$;X;LX$+LEFT$(LZ$,8)
40 PRINTLV$:X=X-1
50 IFX=1THENLX$=LY$
60 PRINTX;LX$+LZ$
70 IFX=0THEN END ELSE 30

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: