99 Bottles of Beer/Basic: Difference between revisions

no edit summary
m (Syntax highlighting fixup)
No edit summary
 
(10 intermediate revisions by 5 users not shown)
Line 6:
__toc__
=={{header|BASIC}}==
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">suffix$ = "s"
FOR bottles = 4 TO 1 STEP -1
PRINT STR$(bottles) + " bottle" + suffix$ + " of beer on the wall, ";
PRINT STR$(bottles) + " bottle" + suffix$ + " of beer."
PRINT "Take one down and pass it around, ";
IF bottles > 1 THEN
IF bottles = 2 THEN suffix$ = ""
PRINT STR$(bottles - 1) + " bottle" + suffix$ + " of beer on the wall..."
ELSE
PRINT "no more bottles of beer on the wall..."
END IF
PRINT
NEXT bottles
 
PRINT "No more bottles of beer on the wall, no more bottles of beer."
PRINT "Go to the store and buy some more, 99 bottles of beer on the wall."
END</syntaxhighlight>
 
==={{header|QuickBASIC}}===
{{works with|QuickBASIC|4.5}}
====Sound====
This version plays the tune 100 times while printing out the lyrics (not synchronized).
<syntaxhighlight lang="qbasic">PLAY "<"
FOR x = 99 TO 0 STEP -1
PRINT x; "bottles of beer on the wall"
PRINT x; "bottles of beer"
PRINT "Take one down, pass it around"
PRINT x-1; "bottles of beer on the wall"
PRINT
PLAY "e-8e-8e-8<b-8b-8b-8>e-8e-8e-8e-4"'X bottles of beer on the wall
PLAY "f8f8f8c8c8c8f4"'X bottles of beer
PLAY "d4d8d8 N0 d8d8d8d4"'take one down, pass it around
PLAY "<a+8a+8a+8>c8c8d8d+8d+8d+8d+4"'X-1 bottles of beer on the wall
NEXT x</syntaxhighlight>
 
====Text====
<syntaxhighlight lang="qbasic">FOR x = 99 TO 1 STEP -1
PRINT x; "bottles of beer on the wall"
PRINT x; "bottles of beer"
PRINT "Take one down, pass it around"
PRINT x-1; "bottles of beer on the wall"
PRINT
NEXT x</syntaxhighlight>
 
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="applesoft basicqbasic">H$ = "HELLO, WORLD!":B$ = " BOTTLES OF BEER":N$ = CHR$ (13):W$ = " ON THE WALL" + N$: FOR B = 99 TO 1 STEP - 1: PRINT B;B$W$B" "B$N$"TAKE ONE DOWN, PASS IT AROUND"N$B - 1;B$W$: NEXT </syntaxhighlight>
 
==={{header|BaCon}}===
With lyrics and punctuation taken from the 99-bottles-of-beer.net site.
<syntaxhighlight lang="freebasic">' 99 bottles of beer on the wall
Line 123 ⟶ 77:
next x
</syntaxhighlight>
 
 
==={{header|BBC BASIC}}===
'''Versión más clásica'''
<syntaxhighlight lang="bbcbasic">REM 99 bottles of beer song BBC BASIC version
REM 99 bottles of beer song BBC BASIC version
REM original code by Stelio Passaris (stelio.net)
:
Line 148 ⟶ 100:
PRINT"Go to the store and buy some more,"
PRINT"99 bottles of beer on the wall."
VDU15:REM deshabilita el modo de paginación</syntaxhighlight>
</syntaxhighlight>
 
Alternative version:
 
==={{header|BBC BASIC}}===
 
<syntaxhighlight lang="bbcbasic">
Line 189 ⟶ 139:
</syntaxhighlight>
 
==={{header|Commodore BASICbootBASIC}}===
In bootBASIC lines are limited to 19 characters.
<syntaxhighlight lang="BASIC">
5 a=99
10 print a ;
20 print " bottle";
22 if a-1 print "s";
24 print " ";
30 print "of beer ";
40 print "on the ";
50 print "wall!"
60 print a ;
70 print " bottle";
72 if a-1 print "s";
74 print " ";
80 print "of beer!"
90 print "Take one ";
100 print "down, pass";
110 print " it around!"
115 a=a-1
120 print a ;
130 print " bottle";
132 if a-1 print "s";
134 print " ";
140 print "of beer ";
150 print "on the ";
160 print "wall!"
170 print
180 if a goto 10
</syntaxhighlight>
 
==={{header|Commander X16 BASIC}}===
<syntaxhighlight lang="BASIC">
10 PSGINIT
20 PSGPLAY 0, "T220L4"
30 FOR Z=99 TO 1 STEP -1
40 PRINT Z; "BOTTLE";
50 IF Z <> 1 THEN PRINT "S";
60 PRINT " ";
70 PRINT "OF BEER ON THE WALL!"
80 PSGPLAY 0,"GGGDDDGGGG2."
90 PRINT Z; "BOTTLE";
100 IF Z <> 1 THEN PRINT "S";
110 PRINT " ";
120 PRINT "OF BEER!"
130 PSGPLAY 0,"AAAEEES0A2.A2.S1"
140 PRINT " TAKE ONE DOWN"
150 PSGPLAY 0,"F+2F+F+2."
160 PRINT " PASS IT AROUND"
170 PSGPLAY 0,"F+F+F+F+2."
180 PRINT Z-1; "BOTTLE";
190 IF Z <> 2 THEN PRINT "S";
200 PRINT " ";
210 PRINT "OF BEER ON THE WALL!"
220 PSGPLAY 0,"DDDDEF+GGGG2."
230 PRINT
240 NEXT Z
</syntaxhighlight>
 
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{works with|GW-BASIC}}
<syntaxhighlight lang="qbasic">10 cls
20 s$ = "s"
30 for bottles = 99 to 1 step -1
40 print bottles "bottle" s$ " of beer on the wall, "
50 print bottles "bottle" s$ " of beer."
60 print "Take one down and pass it around, "
70 if bottles = 2 then s$ = ""
80 if bottles > 1 then print (bottles-1)"bottle" s$ " of beer on the wall..." else print "no more bottles of beer on the wall..."
90 print
100 next bottles
110 print "No more bottles of beer on the wall,"
120 print "no more bottles of beer."
130 print "Go to the store and buy some more,"
140 print "99 bottles of beer on the wall."
150 end</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
You may need to remove the semicolon on line 20 when executing on the VIC-20. Also, this looks best on the machines with 40 or more columns.
 
<syntaxhighlight lang="freebasic">10 dim bo$(2):bo$(0)="bottle":bo$(1)="bottles"
10 dim bo$(2):bo$(0)="bottle":bo$(1)="bottles"
15 print chr$(147);chr$(14);"99 Bottles of Beer Song"
20 print:print "Start with how many bottles";
Line 211 ⟶ 238:
130 if k$="q" then end
135 rem move to next verse
140 print:next c</syntaxhighlight>
 
</syntaxhighlight>
==={{header|Craft Basic}}===
<syntaxhighlight lang="basic">'99 bottles of beer on the wall
 
for beer = 99 to 1 step - 1
 
if beer > 1 then
 
print beer, " bottles of beer on the wall."
print beer, " bottles of beer!"
 
endif
 
if beer = 1 then
 
print beer, " bottle of beer on the wall."
print "1 more bottle of beer!"
 
endif
 
print "take one down and pass it around..."
 
wait
 
next beer
 
alert "All out of beer!"
 
end</syntaxhighlight>
 
==={{header|Creative Basic}}===
Line 357 ⟶ 412:
NEXT X
 
RETURN</syntaxhighlight>
</syntaxhighlight>
====console only version====
Rather quickly written and dirty.
Line 471 ⟶ 525:
END
 
RETURN</syntaxhighlight>
</syntaxhighlight>
 
==={{header|FBSL}}===
Line 586 ⟶ 639:
DATA "No more","Go to the store and buy some more. 99"
END</syntaxhighlight>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasic">
b$ = " bottles"
for bottles = 99 to 1 step -1
if (bottles = 1) then b$ = " bottle" : fi
print bottles, b$, " of beer on the wall, "
print bottles , b$, " of beer"
print "Take one down, pass it around, "
if bottles = 1 then
print "no more bottles of beer on the wall.\n"
else
print bottles - 1, b$, " of beer on the wall."
print
end if
next bottles
end
</syntaxhighlight>
 
 
==={{header|GW-BASIC}}===
 
Just a basic loop counting down to one. No big deal. Note that at BOTTLES=1, it is not
grammatically correct.
Line 621 ⟶ 653:
 
==={{header|Integer BASIC}}===
 
IMPORTANT NOTE: Integer BASIC was written (and hand-assembled by Woz himself)
for the Apple 1 and original Apple 2.
Line 672 ⟶ 703:
 
==={{header|Microsoft Small Basic}}===
 
<syntaxhighlight lang="microsoftsmallbasic">
For n = 99 To 1 Step -1
Line 726 ⟶ 756:
280 PRINT "Go to the store and buy some more,"
290 PRINT "99 bottles of beer on the wall."
300 END</syntaxhighlight>
</syntaxhighlight>
 
==={{header|MSX Basic}}===
<syntaxhighlight lang="qbasic">10 FOR X = 99 TO 1 STEP -1
 
<syntaxhighlight lang="msxbasic">
10 FOR X = 99 TO 1 STEP -1
20 PRINT X; "bottles of beer on the wall"
30 PRINT X; "bottles of beer"
Line 738 ⟶ 765:
50 PRINT X-1; "bottles of beer on the wall"
60 PRINT
70 NEXT X</syntaxhighlight>
</syntaxhighlight>
 
==={{header|OxygenBasic}}===
<syntaxhighlight lang="qbasic">int x=99
int x=99
string cr,tab,pr,bottles,bottlem,remain
cr=chr(13) chr(10)
Line 770 ⟶ 795:
next
'
putfile "t.txt",pr </syntaxhighlight>
</syntaxhighlight>
 
==={{header|PowerBASIC}}===
Line 896 ⟶ 920:
PRINT
NEXT</syntaxhighlight>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">suffix$ = "s"
FOR bottles = 4 TO 1 STEP -1
PRINT STR$(bottles) + " bottle" + suffix$ + " of beer on the wall, ";
PRINT STR$(bottles) + " bottle" + suffix$ + " of beer."
PRINT "Take one down and pass it around, ";
IF bottles > 1 THEN
IF bottles = 2 THEN suffix$ = ""
PRINT STR$(bottles - 1) + " bottle" + suffix$ + " of beer on the wall..."
ELSE
PRINT "no more bottles of beer on the wall..."
END IF
PRINT
NEXT bottles
 
PRINT "No more bottles of beer on the wall, no more bottles of beer."
PRINT "Go to the store and buy some more, 99 bottles of beer on the wall."
END</syntaxhighlight>
 
==={{header|QuickBASIC}}===
{{works with|QuickBASIC|4.5}}
====Sound====
This version plays the tune 100 times while printing out the lyrics (not synchronized).
<syntaxhighlight lang="qbasic">PLAY "<"
FOR x = 99 TO 0 STEP -1
PRINT x; "bottles of beer on the wall"
PRINT x; "bottles of beer"
PRINT "Take one down, pass it around"
PRINT x-1; "bottles of beer on the wall"
PRINT
PLAY "e-8e-8e-8<b-8b-8b-8>e-8e-8e-8e-4"'X bottles of beer on the wall
PLAY "f8f8f8c8c8c8f4"'X bottles of beer
PLAY "d4d8d8 N0 d8d8d8d4"'take one down, pass it around
PLAY "<a+8a+8a+8>c8c8d8d+8d+8d+8d+4"'X-1 bottles of beer on the wall
NEXT x</syntaxhighlight>
 
====Text====
<syntaxhighlight lang="qbasic">FOR x = 99 TO 1 STEP -1
PRINT x; "bottles of beer on the wall"
PRINT x; "bottles of beer"
PRINT "Take one down, pass it around"
PRINT x-1; "bottles of beer on the wall"
PRINT
NEXT x</syntaxhighlight>
 
==={{header|REALbasic}}===
Line 921 ⟶ 992:
end if
next bottles</syntaxhighlight>
 
==={{header|Sinclair ZX81 BASIC}}===
Scrolls after each line so doesn't run out of screen space and stop prematurely!
<syntaxhighlight lang="basic">10 FOR N=99 TO 1 STEP -1
20 SCROLL
30 PRINT STR$(N)+" BOTTLE"+("S" AND N<>1)+" OF BEER ON THE WALL"
40 SCROLL
50 PRINT STR$(N)+" BOTTLE"+("S" AND N<>1)+" OF BEER"
60 SCROLL
70 PRINT "TAKE ONE DOWN, PASS IT AROUND"
80 SCROLL
90 PRINT STR$(N-1)+" BOTTLE"+("S" AND N<>2)+" OF BEER ON THE WALL"
100 SCROLL
110 NEXT N</syntaxhighlight>
 
==={{header|smart BASIC}}===
Line 943 ⟶ 1,028:
DATA "No more","Go to the store and buy some more. 99"
END</syntaxhighlight>
 
==={{header|Sinclair ZX81 BASIC}}===
Scrolls after each line so doesn't run out of screen space and stop prematurely!
<syntaxhighlight lang="basic">10 FOR N=99 TO 1 STEP -1
20 SCROLL
30 PRINT STR$(N)+" BOTTLE"+("S" AND N<>1)+" OF BEER ON THE WALL"
40 SCROLL
50 PRINT STR$(N)+" BOTTLE"+("S" AND N<>1)+" OF BEER"
60 SCROLL
70 PRINT "TAKE ONE DOWN, PASS IT AROUND"
80 SCROLL
90 PRINT STR$(N-1)+" BOTTLE"+("S" AND N<>2)+" OF BEER ON THE WALL"
100 SCROLL
110 NEXT N</syntaxhighlight>
 
==={{header|TI-83 BASIC}}===
Line 971 ⟶ 1,042:
:Disp "BOTTLES OF BEER"
:Disp "ON THE WALL."
:End</syntaxhighlight>
:End
</syntaxhighlight>
 
 
==={{header|TI-89 BASIC}}===
Line 1,024 ⟶ 1,093:
EndPrgm</syntaxhighlight>
 
==={{header|Tiny BASICTiny_Basic}}===
{{works with|TinyBasic}}
<syntaxhighlight lang="tiny basic">100 LET N=99
<syntaxhighlight lang="basic">100 LET N=99
105 GOSUB 120
110 IF N>0 THEN GOTO 105
Line 1,043 ⟶ 1,113:
180 IF N=1 THEN PRINT N," bottle of beer"
185 IF N>1 THEN PRINT N," bottles of beer"
190 RETURN</syntaxhighlight>
</syntaxhighlight>
 
==={{header|True BASICTrue_BASIC}}===
<syntaxhighlight lang="basic">! TrueBASIC v6.007
! TrueBASIC v6.007
 
LET bottles = 99
Line 1,071 ⟶ 1,139:
PRINT "Press any key to sleep it off"
GET KEY done
END</syntaxhighlight>
END
</syntaxhighlight>
 
==={{header|Visual Basic}}===
Line 1,581 ⟶ 1,648:
...</pre>
 
====<s>More</s>D<s> </s>R<s>con</s>U<s>current</s>NKconcurrent====
<syntaxhighlight lang="vbnet">Module Program
Function Plural(count As Integer) As String
Line 1,670 ⟶ 1,737:
{{trans|Microsoft Small Basic}}
{{works with|Windows XBasic}}
<syntaxhighlight lang="xbasic">PROGRAM "99bottles"
PROGRAM "99bottles"
VERSION "0.0001"
 
Line 1,696 ⟶ 1,762:
NEXT n@@
END FUNCTION
END PROGRAM</syntaxhighlight>
 
</syntaxhighlight>
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasic">b$ = " bottles"
for bottles = 99 to 1 step -1
if (bottles = 1) then b$ = " bottle" : fi
print bottles, b$, " of beer on the wall, "
print bottles , b$, " of beer"
print "Take one down, pass it around, "
if bottles = 1 then
print "no more bottles of beer on the wall.\n"
else
print bottles - 1, b$, " of beer on the wall."
print
end if
next bottles
end</syntaxhighlight>
 
==={{header|ZX Spectrum Basic}}===
Line 1,715 ⟶ 1,797:
140 PRINT
150 NEXT i
160 PRINT "Go to the store and buy some more, 99 bottles of beer on the wall."</syntaxhighlight>
 
</syntaxhighlight>
=={{header|VBA}}==
This version uses tail recursion and inline if-statements,
Line 1,767 ⟶ 1,849:
no more bottles of Johnnie Walker
go to the store and buy some more
3 bottles of Johnnie Walker on the wall</pre>
 
</pre>
=={{header|VBScript}}==
===Simple Method===