99 Bottles of Beer/Basic: Difference between revisions
m
Syntax highlighting fixup
mNo edit summary |
Thundergnat (talk | contribs) 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}}
<
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</
==={{header|QuickBASIC}}===
Line 32 ⟶ 31:
====Sound====
This version plays the tune 100 times while printing out the lyrics (not synchronized).
<
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</
====Text====
<
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</
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="applesoft
===BaCon===
With lyrics and punctuation taken from the 99-bottles-of-beer.net site.
<
DECLARE counter$
DECLARE bottle$
Line 87 ⟶ 86:
PRINT counter$, bottle$, ofbeer$, onthewall$ FORMAT "%s %s %s %s.\n"
IF bottles > 0 THEN PRINT
NEXT</
==={{header|BASIC256}}===
<
n4 = 1000 * 60 / 80 / 4
n8 = n4 / 2
Line 123 ⟶ 122:
print
next x
</syntaxhighlight>
==={{header|BBC BASIC}}===
'''Versión más clásica'''
<
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>
==={{header|BBC BASIC}}===
<
N_Bottles = 99
Line 188 ⟶ 187:
END
</syntaxhighlight>
==={{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">
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>
==={{header|Creative Basic}}===
====window version====
<
DEF Close:CHAR
DEF ScreenSizeX,ScreenSizeY:INT
Line 359 ⟶ 358:
RETURN
</syntaxhighlight>
====console only version====
Rather quickly written and dirty.
<
DECLARE SingWallLn()
Line 473 ⟶ 472:
RETURN
</syntaxhighlight>
==={{header|FBSL}}===
This is a OO version, using FBSL v3.5 Beta
<
Class Wall
Line 537 ⟶ 536:
while BeerSong.Sing() <> 99
end while
</syntaxhighlight>
==={{header|FreeBASIC}}===
==== Normal version ====
<
Dim As Integer bottles = 99
Line 561 ⟶ 560:
Print "Press any key to sleep it off"
Sleep</
==== Code golf ====
<
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</
==={{header|FUZE BASIC}}===
<
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</
==={{header|Yabasic}}===
<
b$ = " bottles"
for bottles = 99 to 1 step -1
Line 605 ⟶ 604:
next bottles
end
</syntaxhighlight>
Line 613 ⟶ 612:
grammatically correct.
<
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>
==={{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.
<
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</
==={{header|Liberty BASIC}}===
<
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$</
==={{header|Microsoft Small Basic}}===
<
For n = 99 To 1 Step -1
If n = 1 Then
Line 692 ⟶ 691:
TextWindow.WriteLine("")
EndFor
</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).
<
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>
==={{header|MSX Basic}}===
<syntaxhighlight 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>
==={{header|OxygenBasic}}===
<
int x=99
string cr,tab,pr,bottles,bottlem,remain
Line 772 ⟶ 771:
'
putfile "t.txt",pr
</syntaxhighlight>
==={{header|PowerBASIC}}===
<
#DIM ALL
Line 804 ⟶ 803:
CON.INPUT("Press any key to sleep it off",done$)
END FUNCTION</
==={{header|PureBasic}}===
====Normal version====
<
Define Bottles=99
While Bottles
Line 820 ⟶ 819:
PrintN(#CRLF$+#CRLF$+"Press ENTER to exit"):Input()
CloseConsole()
EndIf</
====An object-oriented solution====
<
Structure WallClass
Line 881 ⟶ 880:
CloseConsole()
EndIf
EndIf</
==={{header|QB64}}===
''CBTJD'': 2020/03/08
* Manages grammatical support for "1 bottle of beer" and "No more bottles of beer".
<
FOR B = 99 TO 1 STEP -1
S$ = STRING$(ABS(B > 1), "s")
Line 896 ⟶ 895:
END SELECT
PRINT
NEXT</
==={{header|REALbasic}}===
Place the following in the "open" event of a console application.
<
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</
==={{header|Run BASIC}}===
<
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</
==={{header|smart BASIC}}===
<
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</
==={{header|Sinclair ZX81 BASIC}}===
Scrolls after each line so doesn't run out of screen space and stop prematurely!
<
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</
==={{header|TI-83 BASIC}}===
<
:For(I,99,1,-1)
:Disp I
Line 973 ⟶ 972:
:Disp "ON THE WALL."
:End
</syntaxhighlight>
==={{header|TI-89 BASIC}}===
<
Local i,plural,clockWas,t,k,wait
"s" → plural
Line 1,023 ⟶ 1,022:
ClockOff
ENdIf
EndPrgm</
==={{header|Tiny BASIC}}===
<
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>
==={{header|True BASIC}}===
<
! TrueBASIC v6.007
Line 1,073 ⟶ 1,072:
GET KEY done
END
</syntaxhighlight>
==={{header|Visual Basic}}===
<
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</
==={{header|Visual Basic .NET}}===
Line 1,114 ⟶ 1,113:
====Classic====
<
Sub Main()
Dim Bottles As Integer
Line 1,133 ⟶ 1,132:
Next
End Sub
End Module</
====String interpolation====
<
Function Plural(count As Integer) As String
Return If(count = 1, "", "s")
Line 1,150 ⟶ 1,149:
Next
End Sub
End Module</
====Mental mutilation beyond hope of regeneration====
<
Option Strict Off
Line 1,181 ⟶ 1,180:
If i > 0 Then GoTo START
End Sub
End Module</
====Python====
<
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</
====With sound====
Line 1,210 ⟶ 1,209:
Options and imports statements (all parts must be in one file):
<
Option Infer On
Option Strict On
Line 1,216 ⟶ 1,215:
Imports System.Globalization
Imports System.Runtime.InteropServices
Imports System.Threading</
Helper to parse command-line arguments:
<
Module ArgHelper
ReadOnly _ArgDict As New Dictionary(Of String, String)()
Line 1,257 ⟶ 1,256:
End If
End Sub
End 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>
{{out}}
Line 1,493 ⟶ 1,492:
====Concurrent====
<
Function Plural(count As Integer) As String
Return If(count = 1, "", "s")
Line 1,509 ⟶ 1,508:
End Sub)
End Sub
End Module</
{{out}}
Line 1,538 ⟶ 1,537:
====Less concurrent====
<
Function Plural(count As Integer) As String
Return If(count = 1, "", "s")
Line 1,557 ⟶ 1,556:
End Sub)
End Sub
End Module</
{{out}}
Line 1,583 ⟶ 1,582:
====<s>More</s>D<s> </s>R<s>con</s>U<s>current</s>NK====
<
Function Plural(count As Integer) As String
Return If(count = 1, "", "s")
Line 1,608 ⟶ 1,607:
End Sub)
End Sub
End Module</
{{out}}
Line 1,671 ⟶ 1,670:
{{trans|Microsoft Small Basic}}
{{works with|Windows XBasic}}
<
PROGRAM "99bottles"
VERSION "0.0001"
Line 1,698 ⟶ 1,697:
END FUNCTION
END PROGRAM
</syntaxhighlight>
==={{header|ZX Spectrum Basic}}===
<
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>
=={{header|VBA}}==
This version uses tail recursion and inline if-statements,
plus a Static variable to count the number of bottles emptied.
<
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</
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===
<
dim i
for i = numBottles to 0 step -1
Line 1,811 ⟶ 1,808:
end function
song 3</
{{Out}}
<pre>3 bottles of beer on the wall
Line 1,842 ⟶ 1,839:
and replacing the code with the result of its evaluation.
<
select case n
case 1
Line 1,899 ⟶ 1,896:
end sub
sing 3</
|