Jump to content

99 Bottles of Beer/Basic: Difference between revisions

m
Syntax highlighting fixup
mNo edit summary
m (Syntax highlighting fixup)
Line 5:
[[99 Bottles of Beer]] done in any of the BASIC-languages.
__toc__
 
=={{header|BASIC}}==
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<langsyntaxhighlight QBasiclang="qbasic">suffix$ = "s"
FOR bottles = 4 TO 1 STEP -1
PRINT STR$(bottles) + " bottle" + suffix$ + " of beer on the wall, ";
Line 26 ⟶ 25:
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</langsyntaxhighlight>
 
==={{header|QuickBASIC}}===
Line 32 ⟶ 31:
====Sound====
This version plays the tune 100 times while printing out the lyrics (not synchronized).
<langsyntaxhighlight lang="qbasic">PLAY "<"
FOR x = 99 TO 0 STEP -1
PRINT x; "bottles of beer on the wall"
Line 43 ⟶ 42:
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</langsyntaxhighlight>
 
====Text====
<langsyntaxhighlight lang="qbasic">FOR x = 99 TO 1 STEP -1
PRINT x; "bottles of beer on the wall"
PRINT x; "bottles of beer"
Line 52 ⟶ 51:
PRINT x-1; "bottles of beer on the wall"
PRINT
NEXT x</langsyntaxhighlight>
 
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="applesoft Applesoft BASICbasic">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 </langsyntaxhighlight>
 
===BaCon===
With lyrics and punctuation taken from the 99-bottles-of-beer.net site.
<langsyntaxhighlight lang="freebasic">' 99 bottles of beer on the wall
DECLARE counter$
DECLARE bottle$
Line 87 ⟶ 86:
PRINT counter$, bottle$, ofbeer$, onthewall$ FORMAT "%s %s %s %s.\n"
IF bottles > 0 THEN PRINT
NEXT</langsyntaxhighlight>
 
==={{header|BASIC256}}===
<langsyntaxhighlight BASIC256lang="basic256">#length of querter and eight note in ms
n4 = 1000 * 60 / 80 / 4
n8 = n4 / 2
Line 123 ⟶ 122:
print
next x
</syntaxhighlight>
</lang>
 
 
==={{header|BBC BASIC}}===
'''Versión más clásica'''
<langsyntaxhighlight lang="bbcbasic">
REM 99 bottles of beer song BBC BASIC version
REM original code by Stelio Passaris (stelio.net)
Line 150 ⟶ 149:
PRINT"99 bottles of beer on the wall."
VDU15:REM deshabilita el modo de paginación
</syntaxhighlight>
</lang>
 
 
==={{header|BBC BASIC}}===
 
<langsyntaxhighlight lang="bbcbasic">
N_Bottles = 99
Line 188 ⟶ 187:
END
</syntaxhighlight>
</lang>
 
==={{header|Commodore BASIC}}===
Line 194 ⟶ 193:
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">
<lang FreeBasic>
10 dim bo$(2):bo$(0)="bottle":bo$(1)="bottles"
15 print chr$(147);chr$(14);"99 Bottles of Beer Song"
Line 213 ⟶ 212:
135 rem move to next verse
140 print:next c
</syntaxhighlight>
</lang>
 
==={{header|Creative Basic}}===
====window version====
<langsyntaxhighlight Creativelang="creative Basicbasic">DEF Win:WINDOW
DEF Close:CHAR
DEF ScreenSizeX,ScreenSizeY:INT
Line 359 ⟶ 358:
 
RETURN
</syntaxhighlight>
</lang>
====console only version====
Rather quickly written and dirty.
<langsyntaxhighlight Creativelang="creative Basicbasic">REM Using the ESC key to exit will not work in console programs under Windows 95/98 or ME.
 
DECLARE SingWallLn()
Line 473 ⟶ 472:
 
RETURN
</syntaxhighlight>
</lang>
 
==={{header|FBSL}}===
This is a OO version, using FBSL v3.5 Beta
<langsyntaxhighlight lang="qbasic">#AppType Console
 
Class Wall
Line 537 ⟶ 536:
while BeerSong.Sing() <> 99
end while
</syntaxhighlight>
</lang>
 
==={{header|FreeBASIC}}===
==== Normal version ====
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Dim As Integer bottles = 99
Line 561 ⟶ 560:
 
Print "Press any key to sleep it off"
Sleep</langsyntaxhighlight>
 
==== Code golf ====
<langsyntaxhighlight lang="freebasic">Var b=" bottle",s="s",f=" of beer",w=" on the wall",_
t="Take one down and pass it around, ",n="o more",p="."
For a As Byte=99 To 1 Step-1
Line 572 ⟶ 571:
?t;"n";n;b;s;f;w;p:?:?"N";n;b;s;f;w;", n";n;b;s;f;p
?"Go to the store and buy some more, 99";b;s;f;w;p
Sleep</langsyntaxhighlight>
 
==={{header|FUZE BASIC}}===
<langsyntaxhighlight lang="qbasic">CLS
DIM s$(1)
READ b,s$(0),s$(1),a$,b$,c$,d$,e$,f$
Line 586 ⟶ 585:
DATA 99,"","s"," bottle"," of beer"," on the wall. ","Take one down, pass it around. "
DATA "No more","Go to the store and buy some more. 99"
END</langsyntaxhighlight>
 
==={{header|Yabasic}}===
<langsyntaxhighlight lang="yabasic">
b$ = " bottles"
for bottles = 99 to 1 step -1
Line 605 ⟶ 604:
next bottles
end
</syntaxhighlight>
</lang>
 
 
Line 613 ⟶ 612:
grammatically correct.
 
<langsyntaxhighlight lang="qbasic">10 FOR BOTTLES = 99 TO 1 STEP -1
20 PRINT BOTTLES " bottles of beer on the wall"
30 PRINT BOTTLES " bottles of beer"
Line 619 ⟶ 618:
50 PRINT BOTTLES-1 " bottles of beer on the wall"
60 NEXT BOTTLES
</syntaxhighlight>
</lang>
 
==={{header|Integer BASIC}}===
Line 628 ⟶ 627:
The UPPER-CASE output of this example accurately represents the only reasonable solution for those target devices, and therefore cannot be "fixed" for mixed case, only deleted.
 
<langsyntaxhighlight Integerlang="integer BASICbasic">E000G (APPLE II)
E000R (APPLE I)
10 REM -------------------------
Line 655 ⟶ 654:
80 PRINT " BOTTLE";: IF B#1 THEN PRINT "S";: PRINT " OF BEER";
90 IF W#1 THEN PRINT " ON THE WALL";: IF W THEN PRINT ".": NEXT W,B: END
RUN</langsyntaxhighlight>
 
==={{header|Liberty BASIC}}===
<langsyntaxhighlight lang="lb">For bottles = 99 To 1 Step -1
song$ = song$ + str$(bottles) + " bottle"
If (bottles > 1) Then song$ = song$ + "s"
Line 670 ⟶ 669:
+ chr$(13) + chr$(10) + "Go to the store and buy some more, 99 bottles of beer on the wall."
 
Print song$</langsyntaxhighlight>
 
==={{header|Microsoft Small Basic}}===
 
<langsyntaxhighlight lang="microsoftsmallbasic">
For n = 99 To 1 Step -1
If n = 1 Then
Line 692 ⟶ 691:
TextWindow.WriteLine("")
EndFor
</syntaxhighlight>
</lang>
 
==={{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).
<langsyntaxhighlight lang="gwbasic">
10 REM 99 Bottles of Beer
20 LET A$ = " bottle"
Line 728 ⟶ 727:
290 PRINT "99 bottles of beer on the wall."
300 END
</syntaxhighlight>
</lang>
 
==={{header|MSX Basic}}===
 
<syntaxhighlight lang="msxbasic">
<lang MSXBasic>
10 FOR X = 99 TO 1 STEP -1
20 PRINT X; "bottles of beer on the wall"
Line 740 ⟶ 739:
60 PRINT
70 NEXT X
</syntaxhighlight>
</lang>
 
==={{header|OxygenBasic}}===
<langsyntaxhighlight lang="qbasic">
int x=99
string cr,tab,pr,bottles,bottlem,remain
Line 772 ⟶ 771:
'
putfile "t.txt",pr
</syntaxhighlight>
</lang>
 
==={{header|PowerBASIC}}===
<langsyntaxhighlight PowerBasiclang="powerbasic">#COMPILE EXE
#DIM ALL
 
Line 804 ⟶ 803:
CON.INPUT("Press any key to sleep it off",done$)
 
END FUNCTION</langsyntaxhighlight>
 
==={{header|PureBasic}}===
====Normal version====
<langsyntaxhighlight PureBasiclang="purebasic">If OpenConsole()
Define Bottles=99
While Bottles
Line 820 ⟶ 819:
PrintN(#CRLF$+#CRLF$+"Press ENTER to exit"):Input()
CloseConsole()
EndIf</langsyntaxhighlight>
 
====An object-oriented solution====
<langsyntaxhighlight PureBasiclang="purebasic">Prototype Wall_Action(*Self, Number.i)
 
Structure WallClass
Line 881 ⟶ 880:
CloseConsole()
EndIf
EndIf</langsyntaxhighlight>
 
==={{header|QB64}}===
''CBTJD'': 2020/03/08
* Manages grammatical support for "1 bottle of beer" and "No more bottles of beer".
<langsyntaxhighlight lang="vb">A$ = "bottle": B$ = " of beer": C$ = " on the wall": D$ = " Take one down, pass it around": E$ = " No more "
FOR B = 99 TO 1 STEP -1
S$ = STRING$(ABS(B > 1), "s")
Line 896 ⟶ 895:
END SELECT
PRINT
NEXT</langsyntaxhighlight>
 
==={{header|REALbasic}}===
Place the following in the "open" event of a console application.
<langsyntaxhighlight lang="vb">dim bottles as Integer = 99
While bottles > 0
Print(str(bottles) + " bottles of beer on the wall")
Line 907 ⟶ 906:
bottles = bottles - 1
Print(str(bottles) + " bottles of beer on the wall")
Wend</langsyntaxhighlight>
 
==={{header|Run BASIC}}===
<langsyntaxhighlight Runbasiclang="runbasic">b$ = " bottles"
for bottles = 99 To 1 Step -1
If (bottles = 1) then b$ = " bottle"
Line 921 ⟶ 920:
print bottles - 1;b$;" of beer on the wall.";chr$(10)
end if
next bottles</langsyntaxhighlight>
 
==={{header|smart BASIC}}===
<langsyntaxhighlight lang="qbasic">READ b,s$(0),s$(1),a$,b$,c$,d$,e$,f$
g$ = CHR$(10)
WHILE b > 0
Line 943 ⟶ 942:
DATA 99,"","s"," bottle"," of beer"," on the wall. ","Take one down, pass it around. "
DATA "No more","Go to the store and buy some more. 99"
END</langsyntaxhighlight>
 
==={{header|Sinclair ZX81 BASIC}}===
Scrolls after each line so doesn't run out of screen space and stop prematurely!
<langsyntaxhighlight 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"
Line 957 ⟶ 956:
90 PRINT STR$(N-1)+" BOTTLE"+("S" AND N<>2)+" OF BEER ON THE WALL"
100 SCROLL
110 NEXT N</langsyntaxhighlight>
 
==={{header|TI-83 BASIC}}===
<langsyntaxhighlight lang="ti83b">PROGRAM:BEER
:For(I,99,1,-1)
:Disp I
Line 973 ⟶ 972:
:Disp "ON THE WALL."
:End
</syntaxhighlight>
</lang>
 
 
==={{header|TI-89 BASIC}}===
<langsyntaxhighlight lang="ti89b">Prgm
Local i,plural,clockWas,t,k,wait
"s" → plural
Line 1,023 ⟶ 1,022:
ClockOff
ENdIf
EndPrgm</langsyntaxhighlight>
 
==={{header|Tiny BASIC}}===
<langsyntaxhighlight Tinylang="tiny BASICbasic">100 LET N=99
105 GOSUB 120
110 IF N>0 THEN GOTO 105
Line 1,045 ⟶ 1,044:
185 IF N>1 THEN PRINT N," bottles of beer"
190 RETURN
</syntaxhighlight>
</lang>
 
==={{header|True BASIC}}===
<langsyntaxhighlight lang="basic">
! TrueBASIC v6.007
 
Line 1,073 ⟶ 1,072:
GET KEY done
END
</syntaxhighlight>
</lang>
 
==={{header|Visual Basic}}===
<langsyntaxhighlight lang="vb">Sub Main()
Const bottlesofbeer As String = " bottles of beer"
Const onthewall As String = " on the wall"
Line 1,108 ⟶ 1,107:
Debug.Print "Go to the store, buy some more"
Debug.Print "99" & bottlesofbeer & onthewall
End Sub</langsyntaxhighlight>
 
==={{header|Visual Basic .NET}}===
Line 1,114 ⟶ 1,113:
 
====Classic====
<langsyntaxhighlight lang="vbnet">Module Module1
Sub Main()
Dim Bottles As Integer
Line 1,133 ⟶ 1,132:
Next
End Sub
End Module</langsyntaxhighlight>
 
====String interpolation====
<langsyntaxhighlight lang="vbnet">Module Program
Function Plural(count As Integer) As String
Return If(count = 1, "", "s")
Line 1,150 ⟶ 1,149:
Next
End Sub
End Module</langsyntaxhighlight>
 
====Mental mutilation beyond hope of regeneration====
<langsyntaxhighlight lang="vbnet">Option Explicit Off
Option Strict Off
 
Line 1,181 ⟶ 1,180:
If i > 0 Then GoTo START
End Sub
End Module</langsyntaxhighlight>
 
====Python====
<langsyntaxhighlight lang="vbnet">Option Strict Off
 
Module Program
Line 1,191 ⟶ 1,190:
Console.Write(String.Join(vbLf,Enumerable.Range(1,99).Reverse.Select(Function(x)s(x)+a+b+s(x)+a+vbLf+c+s(x-1)+a+b)))
End Sub
End Module</langsyntaxhighlight>
 
====With sound====
Line 1,210 ⟶ 1,209:
 
Options and imports statements (all parts must be in one file):
<langsyntaxhighlight lang="vbnet">Option Explicit On
Option Infer On
Option Strict On
Line 1,216 ⟶ 1,215:
Imports System.Globalization
Imports System.Runtime.InteropServices
Imports System.Threading</langsyntaxhighlight>
 
Helper to parse command-line arguments:
<langsyntaxhighlight lang="vbnet">
Module ArgHelper
ReadOnly _ArgDict As New Dictionary(Of String, String)()
Line 1,257 ⟶ 1,256:
End If
End Sub
End Module</langsyntaxhighlight>
 
Program:
<langsyntaxhighlight lang="vbnet">Module Program
Function GetNumberSyllables(n As Integer) As IEnumerable(Of String)
Static getTensPrefix As Func(Of Integer, IEnumerable(Of String)) =
Line 1,454 ⟶ 1,453:
End Sub
End Module
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,493 ⟶ 1,492:
 
====Concurrent====
<langsyntaxhighlight lang="vbnet">Module Program
Function Plural(count As Integer) As String
Return If(count = 1, "", "s")
Line 1,509 ⟶ 1,508:
End Sub)
End Sub
End Module</langsyntaxhighlight>
 
{{out}}
Line 1,538 ⟶ 1,537:
 
====Less concurrent====
<langsyntaxhighlight lang="vbnet">Module Program
Function Plural(count As Integer) As String
Return If(count = 1, "", "s")
Line 1,557 ⟶ 1,556:
End Sub)
End Sub
End Module</langsyntaxhighlight>
 
{{out}}
Line 1,583 ⟶ 1,582:
 
====<s>More</s>D<s> </s>R<s>con</s>U<s>current</s>NK====
<langsyntaxhighlight lang="vbnet">Module Program
Function Plural(count As Integer) As String
Return If(count = 1, "", "s")
Line 1,608 ⟶ 1,607:
End Sub)
End Sub
End Module</langsyntaxhighlight>
 
{{out}}
Line 1,671 ⟶ 1,670:
{{trans|Microsoft Small Basic}}
{{works with|Windows XBasic}}
<langsyntaxhighlight lang="xbasic">
PROGRAM "99bottles"
VERSION "0.0001"
Line 1,698 ⟶ 1,697:
END FUNCTION
END PROGRAM
</syntaxhighlight>
</lang>
 
==={{header|ZX Spectrum Basic}}===
<langsyntaxhighlight lang="zxbasic">10 DEF FN n$(b)="no more" AND NOT b
20 DEF FN m$(b)=(STR$ b) AND b
30 DEF FN o$(b)="s" AND (b>1)
Line 1,717 ⟶ 1,716:
150 NEXT i
160 PRINT "Go to the store and buy some more, 99 bottles of beer on the wall."
</syntaxhighlight>
</lang>
 
=={{header|VBA}}==
This version uses tail recursion and inline if-statements,
plus a Static variable to count the number of bottles emptied.
 
<langsyntaxhighlight lang="vb">Public Function countbottles(n As Integer, liquid As String) As String
countbottles = IIf(n > 1, Format$(n), IIf(n = 0, "no more", "one")) & " bottle" & IIf(n = 1, "", "s") & " of " & liquid
End Function
Line 1,744 ⟶ 1,742:
End If
End Sub</langsyntaxhighlight>
 
Usage: type "drink 99" in the Immediate window of the VBA editor. If you're not a beer drinker, you can specify your own favourite drink as the second argument; for example:
Line 1,772 ⟶ 1,770:
 
</pre>
 
=={{header|VBScript}}==
===Simple Method===
<langsyntaxhighlight lang="vb">sub song( numBottles )
dim i
for i = numBottles to 0 step -1
Line 1,811 ⟶ 1,808:
end function
 
song 3</langsyntaxhighlight>
{{Out}}
<pre>3 bottles of beer on the wall
Line 1,842 ⟶ 1,839:
and replacing the code with the result of its evaluation.
 
<langsyntaxhighlight lang="vb">function pluralBottles( n )
select case n
case 1
Line 1,899 ⟶ 1,896:
end sub
 
sing 3</langsyntaxhighlight>
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.