99 Bottles of Beer/Basic: Difference between revisions

no edit summary
m (Removed duplicate headers which were causing this task to appear twice in each dialect's task stats. Changed garbled header to 'More concurrent'.)
No edit summary
 
(9 intermediate revisions by 5 users not shown)
Line 5:
[[99 Bottles of Beer]] done in any of the BASIC-languages.
__toc__
=={{header|BASIC}}==
===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>
 
===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 88 ⟶ 42:
NEXT</syntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">#length of querter and eight note in ms
n4 = 1000 * 60 / 80 / 4
Line 124 ⟶ 78:
</syntaxhighlight>
 
==={{header|BBC BASIC}}===
 
===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:
Line 188 ⟶ 139:
</syntaxhighlight>
 
===Commodore BASIC{{header|bootBASIC}}===
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 210 ⟶ 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}}===
====window version====
<syntaxhighlight lang="creative basic">DEF Win:WINDOW
Line 356 ⟶ 412:
NEXT X
 
RETURN</syntaxhighlight>
</syntaxhighlight>
====console only version====
Rather quickly written and dirty.
Line 470 ⟶ 525:
END
 
RETURN</syntaxhighlight>
</syntaxhighlight>
 
==={{header|FBSL}}===
This is a OO version, using FBSL v3.5 Beta
<syntaxhighlight lang="qbasic">#AppType Console
Line 537 ⟶ 591:
</syntaxhighlight>
 
==={{header|FreeBASIC}}===
==== Normal version ====
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
Line 572 ⟶ 626:
Sleep</syntaxhighlight>
 
==={{header|FUZE BASIC}}===
<syntaxhighlight lang="qbasic">CLS
DIM s$(1)
Line 586 ⟶ 640:
END</syntaxhighlight>
 
===Yabasic{{header|GW-BASIC}}===
<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>
 
 
===GW-BASIC===
 
Just a basic loop counting down to one. No big deal. Note that at BOTTLES=1, it is not
grammatically correct.
Line 619 ⟶ 652:
</syntaxhighlight>
 
==={{header|Integer BASIC}}===
 
IMPORTANT NOTE: Integer BASIC was written (and hand-assembled by Woz himself)
for the Apple 1 and original Apple 2.
Line 655 ⟶ 687:
RUN</syntaxhighlight>
 
==={{header|Liberty BASIC}}===
<syntaxhighlight lang="lb">For bottles = 99 To 1 Step -1
song$ = song$ + str$(bottles) + " bottle"
Line 670 ⟶ 702:
Print song$</syntaxhighlight>
 
==={{header|Microsoft Small Basic}}===
 
<syntaxhighlight lang="microsoftsmallbasic">
For n = 99 To 1 Step -1
Line 692 ⟶ 723:
</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
{{trans|BBC BASIC}}
The cases of 99 bottles and of 1 bottle are extracted from the loop. The variable <code>S$</code> is replaced by litterals, <code>T$</code> is divided into two variables (In Minimal BASIC strings assignable to string variables may contain up to 18 chars).
Line 725 ⟶ 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 737 ⟶ 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 769 ⟶ 795:
next
'
putfile "t.txt",pr </syntaxhighlight>
</syntaxhighlight>
 
==={{header|PowerBASIC}}===
<syntaxhighlight lang="powerbasic">#COMPILE EXE
#DIM ALL
Line 804 ⟶ 829:
END FUNCTION</syntaxhighlight>
 
==={{header|PureBasic}}===
====Normal version====
<syntaxhighlight lang="purebasic">If OpenConsole()
Line 881 ⟶ 906:
EndIf</syntaxhighlight>
 
==={{header|QB64}}===
''CBTJD'': 2020/03/08
* Manages grammatical support for "1 bottle of beer" and "No more bottles of beer".
Line 896 ⟶ 921:
NEXT</syntaxhighlight>
 
===REALbasic{{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}}===
Place the following in the "open" event of a console application.
<syntaxhighlight lang="vb">dim bottles as Integer = 99
Line 907 ⟶ 979:
Wend</syntaxhighlight>
 
==={{header|Run BASIC}}===
<syntaxhighlight lang="runbasic">b$ = " bottles"
for bottles = 99 To 1 Step -1
Line 921 ⟶ 993:
next bottles</syntaxhighlight>
 
===smart{{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}}===
<syntaxhighlight lang="qbasic">READ b,s$(0),s$(1),a$,b$,c$,d$,e$,f$
g$ = CHR$(10)
Line 943 ⟶ 1,029:
END</syntaxhighlight>
 
===Sinclair ZX81{{header|TI-83 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>
 
===TI-83 BASIC===
<syntaxhighlight lang="ti83b">PROGRAM:BEER
:For(I,99,1,-1)
Line 970 ⟶ 1,042:
:Disp "BOTTLES OF BEER"
:Disp "ON THE WALL."
:End</syntaxhighlight>
:End
</syntaxhighlight>
 
 
==={{header|TI-89 BASIC}}===
<syntaxhighlight lang="ti89b">Prgm
Local i,plural,clockWas,t,k,wait
Line 1,023 ⟶ 1,093:
EndPrgm</syntaxhighlight>
 
===Tiny BASIC{{header|Tiny_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,042 ⟶ 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>
 
===True BASIC{{header|True_BASIC}}===
<syntaxhighlight lang="basic">! TrueBASIC v6.007
! TrueBASIC v6.007
 
LET bottles = 99
Line 1,070 ⟶ 1,139:
PRINT "Press any key to sleep it off"
GET KEY done
END</syntaxhighlight>
END
</syntaxhighlight>
 
==={{header|Visual Basic}}===
<syntaxhighlight lang="vb">Sub Main()
Const bottlesofbeer As String = " bottles of beer"
Line 1,108 ⟶ 1,176:
End Sub</syntaxhighlight>
 
==={{header|Visual Basic .NET}}===
'''Platform:''' [[.NET]]
 
Line 1,666 ⟶ 1,734:
...</pre>
 
==={{header|XBasic}}===
{{trans|Microsoft Small Basic}}
{{works with|Windows XBasic}}
<syntaxhighlight lang="xbasic">PROGRAM "99bottles"
PROGRAM "99bottles"
VERSION "0.0001"
 
Line 1,695 ⟶ 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}}===
<syntaxhighlight lang="zxbasic">10 DEF FN n$(b)="no more" AND NOT b
20 DEF FN m$(b)=(STR$ b) AND b
Line 1,714 ⟶ 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,
plus a Static variable to count the number of bottles emptied.
Line 1,766 ⟶ 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>
 
=={{header|VBScript}}==
</pre>
==VBScript==
===Simple Method===
<syntaxhighlight lang="vb">sub song( numBottles )