99 bottles of beer: Difference between revisions
PascalABC.NET
(PascalABC.NET) |
|||
(319 intermediate revisions by 100 users not shown) | |||
Line 9:
<blockquote>
::: 99 bottles of beer on the wall<br/>
::: 99 bottles of beer<br/>
::: Take one down, pass it around<br/>
::: 98 bottles of beer on the wall<br/><br/>
::: 98 bottles of beer on the wall<br/>
::: 98 bottles of beer<br/>
::: Take one down, pass it around<br/>
::: 97 bottles of beer on the wall
</blockquote>
... and so on, until reaching '''0''' (zero).
Grammatical support for
As with any puzzle, try to do it in as creative/concise/comical a way
Line 28:
{{Template:Strings}}
Line 43 ⟶ 40:
=={{header|0815}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|11l}}==
{{trans|Python}}
<syntaxhighlight lang="11l">L(i) (99..1).step(-1)
print(i‘ bottles of beer on the wall’)
print(i‘ bottles of beer’)
print(‘Take one down, pass it around’)
print((i - 1)" bottles of beer on the wall\n")</syntaxhighlight>
=={{header|360 Assembly}}==
Line 51 ⟶ 57:
=={{header|6800 Assembly}}==
See [[99 Bottles of Beer/Assembly]]
=={{header|68000 Assembly}}==
See [[99 Bottles of Beer/Assembly]]
=={{header|8080 Assembly}}==
See [[99 Bottles of Beer/Assembly]]
=={{header|8th}}==
<
\ 99 bottles of beer on the wall:
: allout "no more bottles" ;
Line 75 ⟶ 87:
' beers 1 99 loop- bye
</syntaxhighlight>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program bootleBeer64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ MAXI, 99
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessLine1: .asciz "@ bottles of beer on the wall\n"
szMessLine2: .ascii "@ bottles of beer\n"
.asciz "Take one down, pass it around\n"
szMessLine3: .asciz "@ bottles of beer on the wall\n\n"
szMessLine4: .ascii "\nNo more bottles of beer on the wall, no more bottles of beer.\n"
.asciz "Go to the store and buy some more, 99 bottles of beer on the wall.\n"
szCarriageReturn: .asciz "\n"
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: // entry of program
mov x2,#MAXI
1:
mov x0,x2
ldr x1,qAdrsZoneConv
bl conversion10 // call decimal conversion
ldr x0,qAdrszMessLine1
ldr x1,qAdrsZoneConv // insert conversion in message
bl strInsertAtCharInc
bl affichageMess
ldr x0,qAdrszMessLine2
ldr x1,qAdrsZoneConv // insert conversion in message
bl strInsertAtCharInc
bl affichageMess
subs x0,x2,#1
ble 2f
ldr x1,qAdrsZoneConv
bl conversion10 // call decimal conversion
ldr x0,qAdrszMessLine3
ldr x1,qAdrsZoneConv // insert conversion in message
bl strInsertAtCharInc
bl affichageMess
2:
subs x2,x2,1
bgt 1b
ldr x0,qAdrszMessLine4
bl affichageMess
100: // standard end of the program
mov x0, #0 // return code
mov x8, #EXIT // request to exit program
svc #0 // perform the system call
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrszMessLine1: .quad szMessLine1
qAdrszMessLine2: .quad szMessLine2
qAdrszMessLine3: .quad szMessLine3
qAdrszMessLine4: .quad szMessLine4
qAdrsZoneConv: .quad sZoneConv
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
=={{header|ABAP}}==
<
DATA lv_no_bottles(2) TYPE n VALUE 99.
Line 95 ⟶ 192:
WRITE ' bottles of beer on the wall'.
WRITE /.
ENDDO.</
or (With ABAP 7.40)
<
DATA it_99_bottles TYPE TABLE OF string WITH EMPTY KEY.
Line 117 ⟶ 214:
cl_demo_output=>write( it_99_bottles ).
cl_demo_output=>display( ).
</syntaxhighlight>
=={{header|ABC}}==
<syntaxhighlight lang="abc">HOW TO RETURN bottles n:
SELECT:
n<0: RETURN "99 bottles"
n=0: RETURN "No more bottles"
n=1: RETURN "1 bottle"
n>1: RETURN "`n` bottles"
HOW TO SING VERSE n:
WRITE "`bottles n` of beer on the wall,"/
WRITE "`bottles n` of beer,"/
SELECT:
n=0: WRITE "Go to the store and buy some more,"/
n=1: WRITE "Take it down and pass it around,"/
n>1: WRITE "Take one down and pass it around,"/
WRITE "`bottles (n-1)` of beer on the wall."/
WRITE /
FOR n IN {0..99}:
SING VERSE 99-n</syntaxhighlight>
=={{header|ACL2}}==
See [[99 Bottles of Beer/Lisp]]
=={{header|Acornsoft Lisp}}==
See [[99 Bottles of Beer/Lisp]]
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Bottles(BYTE i)
IF i=0 THEN
Print("No more")
ELSE
PrintB(i)
FI
Print(" bottle")
IF i#1 THEN
Print("s")
FI
RETURN
PROC Main()
BYTE i=[99]
WHILE i>0
DO
Bottles(i) PrintE(" of beer on the wall,")
Bottles(i) PrintE(" of beer,")
Print("Take ")
IF i>1 THEN
Print("one")
ELSE
Print("it")
FI
PrintE(" down and pass it around,")
i==-1
Bottles(i) PrintE(" of beer on the wall.")
IF i>0 THEN
PutE()
FI
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/99_bottles_of_beer.png Screenshot from Atari 8-bit computer]
<pre>
99 bottles of beer on the wall,
99 bottles of beer,
Take one down and pass it around,
98 bottles of beer on the wall.
...
2 bottles of beer on the wall,
2 bottles of beer,
Take one down and pass it around,
1 bottle of beer on the wall.
1 bottle of beer on the wall,
1 bottle of beer,
Take it down and pass it around,
No more bottles of beer on the wall.
</pre>
=={{header|ActionScript}}==
<
{
trace(numBottles, " bottles of beer on the wall");
Line 129 ⟶ 305:
trace("Take one down, pass it around");
trace(numBottles - 1, " bottles of beer on the wall\n");
}</
=={{header|Ada}}==
===Simple version===
<
procedure Bottles is
Line 144 ⟶ 320:
New_Line;
end loop;
end Bottles;</
===Concurrent version===
with 1 task to print out the information and 99 tasks to specify the number of bottles
<
procedure Tasking_99_Bottles is
Line 185 ⟶ 361:
Task_List(I) := new Counter(I);
end loop;
end Tasking_99_Bottles;</
=={{header|Aime}}==
<
bottles = 99;
Line 197 ⟶ 373:
o_("Take one down, pass it around\n");
o_(bottles -= 1, " bottles of beer on the wall\n\n");
} while (bottles);</
=={{header|Algae}}==
<
# 99 Bottles of Beer on the Wall
# in Algae
Line 221 ⟶ 397:
}
}
</syntaxhighlight>
=={{header|ALGOL 60}}==
<syntaxhighlight lang="algol60">begin
integer n;
for n:= 99 step -1 until 2 do
begin
outinteger(1,n);
outstring(1,"bottles of beer on the wall,");
outinteger(1,n);
outstring(1,"bottles of beer.\nTake one down and pass it around,");
outstring(1,"of beer on the wall...\n\n")
end;
outstring(1," 1 bottle of beer on the wall, 1 bottle of beer.\n");
outstring(1,"Take one down and pass it around, no more bottles of beer on the wall...\n\n");
outstring(1,"No more bottles of beer on the wall, no more bottles of beer.\n");
outstring(1,"Go to the store and buy some more, 99 bottles of beer on the wall.")
end</syntaxhighlight>
=={{header|ALGOL 68}}==
Line 227 ⟶ 423:
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
<!-- {{not works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - printf has been removed}} -->
<
FOR bottles FROM 99 TO 1 BY -1 DO
printf(($z-d" bottles of beer on the wall"l$, bottles));
Line 234 ⟶ 430:
printf(($z-d" bottles of beer on the wall"ll$, bottles-1))
OD
)</
=={{header|ALGOL-M}}==
<
BEGIN
Line 270 ⟶ 466:
END
</syntaxhighlight>
=={{header|AmigaE}}==
<
DEF t: PTR TO CHAR,
s: PTR TO CHAR,
Line 285 ⟶ 481:
IF i > 0 THEN WriteF(t)
ENDFOR
ENDPROC</
=={{header|Apache Ant}}==
Implementation in Apache Ant, due to the limitations of Ant, this requires ant-contrib for arithmetic operations and a dummy target to keep Ant from detecting the loop.
<
<project name="n bottles" default="99_bottles">
Line 330 ⟶ 526:
</target>
</project></
=={{header|Apex}}==
<
for(Integer i = 99; i=0; i--){
system.debug(i + ' bottles of beer on the wall');
Line 341 ⟶ 537:
system.debug('take one down, pass it around');
}
</syntaxhighlight>
=={{header|APL}}==
{{works with|Dyalog APL}}
{{works with|GNU APL}}
===Classic version===
{{trans|J}}
Line 351 ⟶ 549:
bobw ← {(bob ⍵) , ' on the wall'}
beer ← { (bobw ⍵) , ', ', (bob ⍵) , '; take one down and pass it around, ', bobw ⍵-1}
⍝ Dyalog APL invocation
99↑beer¨ ⌽(1-⎕IO)+⍳99
⍝ GNU APL invocation (↑ and ⊃ differ, traditional APL2 meanings)
⊃beer¨ ⌽(1-⎕IO)+⍳99
===One line version===
⍝ Dyalog and GNU APL
⍪{(⍕⍵),' bottles of beer on the wall, take one down and pass it around, ',(⍕⍵-1),' bottles of beer on the wall'}¨⌽⍳99
=={{header|App Inventor}}==
Line 365 ⟶ 572:
===Iteration===
<
set bottles to "bottles"
if beerCount < 99 then
Line 378 ⟶ 585:
log "Take one down, pass it around"
end
log "No more bottles of beer on the wall!"</
===Declaration===
<
on run
set localisations to ¬
Line 497 ⟶ 704:
on unwords(xs)
intercalate(space, xs)
end unwords</
=={{header|Arbre}}==
<syntaxhighlight lang="arbre">
bottle(x):
template: '
Line 524 ⟶ 731:
bottles(99) -> io
</syntaxhighlight>
=={{header|Argile}}==
<
let X be an int
Line 546 ⟶ 752:
.:on the wall:. -> text {
X>17 ? "on the wall", (X>1 ? "on the bwall", "in the buttle")
}</
=={{header|ARM Assembly}}==
See [[99 Bottles of Beer/Assembly]]
=={{header|ArnoldC}}==
As ArnoldC does not feature string concatenation, the numbers of bottles and the rest of the parts of the lyrics are printed on separate lines.
<syntaxhighlight lang="arnoldc">IT'S SHOWTIME
HEY CHRISTMAS TREE is0
YOU SET US UP @NO PROBLEMO
HEY CHRISTMAS TREE bottles
YOU SET US UP 99
STICK AROUND is0
TALK TO THE HAND bottles
TALK TO THE HAND " bottles of beer on the wall"
TALK TO THE HAND bottles
TALK TO THE HAND " bottles of beer"
TALK TO THE HAND "Take one down, pass it around"
GET TO THE CHOPPER bottles
HERE IS MY INVITATION bottles
GET DOWN 1
ENOUGH TALK
TALK TO THE HAND bottles
TALK TO THE HAND " bottles of beer on the wall"
GET TO THE CHOPPER is0
HERE IS MY INVITATION bottles
LET OFF SOME STEAM BENNET 0
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED</syntaxhighlight>
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">s: "s"
loop 99..1 'i [
print ~"|i| bottle|s| of beer on the wall,"
print ~"|i| bottle|s| of beer"
print ~"Take one down, pass it around!"
if 1=i-1 -> s: ""
if? i>1 [
print ~"|i-1| bottle|s| of beer on the wall!"
print ""
]
else -> print "No more bottles of beer on the wall!"
]</syntaxhighlight>
=={{header|AsciiDots}}==
<syntaxhighlight lang="asciidots"> /-99#-.
/>*$_#-$_" bottles of beer on the wall, "-$_#-$" bottles of beer."\
|[-]1#-----" ,dnuora ti ssap dna nwod eno ekaT"_$-----------------/
| |
| | &-".llaw eht no reeb fo selttob 99 ,erom emos yub dna erots eht ot oG"$\
| |/$""-$"No more bottles of beer on the wall, no more bottles of beer."---/
| |\".llaw eht no reeb fo selttob erom on ,dnuora ti ssap dna nwod eno ekaT"$-".reeb fo elttob 1"$\
| | /-$"1 bottle of beer on the wall."-$""-$_"1 bottle of beer on the wall, "------------/
| | /-------\|
| \-*--{=}-\\~$_#-$" bottles of beer on the wall."\
| \-#1/ \-/ |
\----------------------------------------------""$/</syntaxhighlight>
=={{header|Astro}}==
<
(0) => "No more bottles"
(1) => "1 bottle"
Line 563 ⟶ 826:
Take one down, pass it around
{bottles n-1} of beer on the wall\n
"""</
=={{header|Asymptote}}==
<syntaxhighlight lang="asymptote">// Rosetta Code problem: http://rosettacode.org/wiki/99_bottles_of_beer
// by Jjuanhdez, 05/2022
int bottles = 99;
for (int i = bottles; i > 0; --i) {
write(string(i), " bottles of beer on the wall,");
write(string(i), " bottles of beer.");
write("Take one down and pass it around,");
if (i == 1) {
write("no more bottles of beer on the wall...");
} else {
write(string(i-1), " bottles of beer on the wall...");
}
}
write("No more bottles of beer on the wall,");
write("no more bottles of beer.");
write("Go to the store and buy some more,");
write(" 99 bottles of beer on the wall.");</syntaxhighlight>
=={{header|ATS}}==
<syntaxhighlight lang="ats">//
#include
"share/atspre_staload.hats"
Line 594 ⟶ 879:
(* ****** ****** *)
implement main0 () = bottles (99)</
=={{header|AutoHotkey}}==
Line 608 ⟶ 893:
For example, just a sixpack:
<
function bb(n) {
Line 628 ⟶ 913:
}
print "Go to the store and buy some more!"
}</
{{out}}
Line 665 ⟶ 950:
Pauses are added to accommodate the small calculator screen so all of the text can be read.
<
While B
Disp B▶Dec," BOTTLES OF","BEER ON THE WALL"
Line 674 ⟶ 959:
Disp B▶Dec," BOTTLES OF","BEER ON THE WALL",i
getKeyʳ
End</
=={{header|Babel}}==
<
{b " bottles of beer" <
Line 694 ⟶ 979:
< }
-- At the prompt, type 'N beer !' (no quotes), where N is the number of stanzas you desire</
=={{header|BabyCobol}}==
<syntaxhighlight lang="cobol">
* Pointing out some interesting things:
* - BY 0 subclause of VARYING (illegal in some COBOL dialects)
* - PERFORM THROUGH with internal/external GO TOs
* - using non-reserved keywords (END, DATA)
* - ALTER (works the same way in COBOL)
* - fall-through from MANY-BOTTLES
* - the last NEXT SENTENCE does nothing (plays the role of EXIT)
IDENTIFICATION DIVISION.
PROGRAM-ID. 99 BOTTLES.
DATA DIVISION.
01 DATA PICTURE IS 999.
PROCEDURE DIVISION.
LOOP VARYING DATA FROM 99 BY 0
PERFORM COUNT-BOTTLES THROUGH END
DISPLAY DATA "bottles of beer"
DISPLAY "Take one down, pass it around"
SUBTRACT 1 FROM DATA
IF DATA = 1
THEN ALTER COUNT-BOTTLES TO PROCEED TO SINGLE-BOTTLE
END
PERFORM COUNT-BOTTLES THROUGH END
DISPLAY ""
END.
NO-BOTTLES-LEFT.
DISPLAY "No bottles of beer on the wall"
DISPLAY ""
DISPLAY "Go to the store and buy some more"
DISPLAY "99 bottles of beer on the wall".
STOP.
COUNT-BOTTLES.
GO TO MANY-BOTTLES.
SINGLE-BOTTLE.
DISPLAY DATA "bottle of beer on the wall".
GO TO NO-BOTTLES-LEFT.
MANY-BOTTLES.
DISPLAY DATA "bottles of beer on the wall".
END.
NEXT SENTENCE.
</syntaxhighlight>
=={{header|BASIC}}==
Line 702 ⟶ 1,029:
==={{header|BaCon}}===
See [[99 Bottles of Beer/Basic#BaCon]]
==={{header|BASIC256}}===
See [[99 Bottles of Beer/Basic]]
==={{header|BBC BASIC}}===
See [[99 Bottles of Beer/Basic]]
==={{header|Commodore BASIC}}===
See [[99 Bottles of Beer/Basic#Commodore_BASIC]]
==={{header|Craft Basic}}===
See [[99 Bottles of Beer/Basic#Craft_Basic]]
==={{header|Creative Basic}}===
See [[99 Bottles of Beer/Basic]]
==={{header|FBSL}}===
Line 710 ⟶ 1,052:
==={{header|FUZE BASIC}}===
See [[99 Bottles of Beer/Basic]]
==={{header|GW-BASIC}}===
See [[99 Bottles of Beer/Basic]]
Line 719 ⟶ 1,064:
==={{header|Microsoft Small Basic}}===
See [[99 Bottles of Beer/Basic]]
==={{header|Minimal BASIC}}===
See [[99 Bottles of Beer/Basic]]
==={{header|MSX Basic}}===
See [[99 Bottles of Beer/Basic]]
Line 728 ⟶ 1,079:
==={{header|PureBasic}}===
See [[99 Bottles of Beer/Basic]]
==={{header|QB64}}===
See [[99 Bottles of Beer/Basic]]
==={{header|QBasic}}===
See [[99 Bottles of Beer/Basic]]
==={{header|QuickBASIC}}===
See [[99 Bottles of Beer/Basic]]
Line 734 ⟶ 1,094:
==={{header|Run BASIC}}===
See [[99 Bottles of Beer/Basic]]
==={{header|Sinclair ZX81 BASIC}}===
See [[99 Bottles of Beer/Basic]]
Line 743 ⟶ 1,106:
==={{header|TI-89 BASIC}}===
See [[99 Bottles of Beer/Basic]]
==={{header|Tiny BASIC}}===
See [[99 Bottles of Beer/Basic]]
Line 749 ⟶ 1,115:
==={{header|Visual Basic}}===
See [[99 Bottles of Beer/Basic]]
==={{header|Visual Basic .NET}}===
See [[99 Bottles of Beer/Basic]]
==={{header|XBasic}}===
See [[99 Bottles of Beer/Basic]]
==={{header|Yabasic}}===
See [[99 Bottles of Beer/Basic]]
Line 760 ⟶ 1,135:
<!--- works with C syntax highlighting --->
<syntaxhighlight lang="c">
const bottle = " bottle"
const plural = "s"
Line 904 ⟶ 1,279:
// vim: set syntax=c ts=4 sw=4 et:
</syntaxhighlight>
=={{header|Bc}}==
Line 910 ⟶ 1,285:
{{works with|GNU bc|1.06}}
<
while ( 1 ) {
print i , " bottles of beer on the wall\n";
Line 923 ⟶ 1,298:
print i , " bottle of beer on the wall\n";
print i , " bottle of beer\nTake it down, pass it around\nno more bottles of beer on the wall\n";
quit</
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">get "libhdr"
let number(n) be
test n=0
then writes("No more")
else writen(n)
let plural(n) be
test n=1
then writes(" bottle")
else writes(" bottles")
let bottles(n) be
$( number(n)
plural(n)
$)
let verse(n) be
$( bottles(n)
writes(" of beer on the wall,*N")
bottles(n)
writes(" of beer,*NTake ")
test n=1
then writes("it")
else writes("one")
writes(" down and pass it around,*N")
bottles(n-1)
writes(" of beer on the wall!*N*N")
$)
let start() be
for n = 99 to 1 by -1 do verse(n)</syntaxhighlight>
=={{header|beeswax}}==
Line 929 ⟶ 1,338:
Straightforward implementation, displaying the full lyrics given on [ http://99-bottles-of-beer.net/ ]
<syntaxhighlight lang="beeswax">
> NN p
> d#_8~2~(P~3~.~1~>{` bottles of beer on the wall, `{` bottles of beer.`q
Line 938 ⟶ 1,347:
>N`No more bottles of beer on the wall, no more bottles of beer.`N q
;`.llaw eht no reeb fo selttob 99 ,erom emos yub dna erots eht ot oG`<
</syntaxhighlight>
A much more “economic” version that tries to avoid repetition at the price of complicated conditional jumps and self-modifying code that takes up more place than the actual strings themselves.
Output is the same as in the straightforward version.
<syntaxhighlight lang="beeswax">
#D@.9~2~@M.7~P9zE `N`p
DMM@.9@.~2~.++~5zE `n`>`o`p
Line 954 ⟶ 1,363:
>^^^^^^^^^; .# b XgNN < bM` ,dnuora ti ssap`<
d^^^^^^^^^^^^^^^^X~3~P(~2~8` ,erom emos yub dna erots eht ot`` oG`<
</syntaxhighlight>
=={{header|Befunge}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|BlitzMax}}==
<syntaxhighlight lang="blitzmax">local bot:int = 99
repeat
print string(bot)+" bottles of beer on the wall,"
print string(bot)+" bottles of beer."
print "Take one down, pass it around,"
bot:-1
print string(bot)+" bottles of beer on the wall."
print
until bot = 1
print "1 bottle of beer on the wall,"
print "1 bottle of beer."
print "Take it down, pass it around,"
print "No more bottles of beer on the wall!"</syntaxhighlight>
=={{header|BlooP}}==
Output is always in caps in the interpreter I use, but I typed the input in correct case to spare those whose interpreter might do lowercase and don't want to have this song shouted at them ;D.
<
DEFINE PROCEDURE ''MINUS'' [A,B]:
BLOCK 0: BEGIN
Line 996 ⟶ 1,422:
BOTTLES[99];
</syntaxhighlight>
=={{header|Bracmat}}==
Line 1,010 ⟶ 1,436:
Code to save to BottlesOfBeer.bra:
<
See http://99-bottles-of-beer.net/}
Line 1,069 ⟶ 1,495:
new'X;
</syntaxhighlight>
=={{header|Brainf***}}==
Line 1,075 ⟶ 1,501:
=={{header|Brat}}==
<
p "#{n} bottles of beer on the wall, #{n} bottles of beer!"
p "Take one down, pass it around, #{n - 1} bottle#{true? n > 2 's' ''} of beer on the wall."
Line 1,081 ⟶ 1,507:
p "One bottle of beer on the wall, one bottle of beer!"
p "Take one down, pass it around, no more bottles of beer on the wall."</
=={{header|Bruijn}}==
<syntaxhighlight lang="bruijn">
:import std/Combinator .
:import std/Number .
:import std/String .
main [y [[=?0 case-end case-rec]] (+99)]
case-rec n ++ t1 ++ n ++ t2 ++ t3 ++ n ++ t1 ++ "\n" ++ (1 --0)
n number→string 0
t1 " bottles of beer on the wall\n"
t2 " bottles of beer\n"
t3 "Take one down, pass it around\n"
case-end empty
</syntaxhighlight>
=={{header|BQN}}==
<syntaxhighlight lang="bqn">Pl ← {(𝕩≠1)/"s"}
{𝕨∾(@+10)∾𝕩}´{(•Fmt 𝕨)∾" "∾𝕩}´¨∾{
⟨
⟨𝕩,"bottle"∾(Pl 𝕩)∾" of beer on the wall"⟩
⟨𝕩,"bottle"∾(Pl 𝕩)∾" of beer"⟩
⟨"Take one down, pass it around"⟩
⟨𝕩-1,"bottle"∾(Pl 𝕩-1)∾" of beer on the wall"∾@+10⟩
⟩
}¨⌽1+↕99</syntaxhighlight>
<code>•Fmt</code> is used to convert numbers to strings.
<code>Pl</code> tells whether the number is singular or plural.
Then, the two folds join all the individual lines together.
=={{header|C}}==
{{trans|C++}}
=== The simple solution ===
<
* 99 Bottles, C, KISS (i.e. keep it simple and straightforward) version
*/
Line 1,113 ⟶ 1,571:
return 0;
}</
=== A recursive solution ===
<
int main(int argc, char *argv[])
Line 1,132 ⟶ 1,590:
printf("%d bottle%c of beer on the wall\n\n", argc - 1, (argc - 1) == 1?'\0': 's');
return argc - 1;
}</
=== Code golf ===
<
main(){_=100;while(--_)printf("%i bottle%s of beer in the wall,\n%i bottle%"
"s of beer.\nTake one down, pass it round,\n%s%s\n\n",_,_-1?"s":"",_,_-1?"s"
:"",_-1?(char[]){(_-1)/10?(_-1)/10+48:(_-1)%10+48,(_-1)/10?(_-1)%10+48:2+30,
(_-1)/10?32:0,0}:"",_-1?"bottles of beer in the wall":"No more beers");}</
=== A preprocessor solution ===
Line 1,147 ⟶ 1,605:
Well, with the preprocessor, that's indeed possible:
<
#include <stdio.h>
Line 1,176 ⟶ 1,634:
(void) printf(SONG);
return EXIT_SUCCESS;
}</
An inspection of the generated executable proves that it indeed contains the complete text of the song in one block.
===The bottled version===
WYSIWYG (with correct plurals and can buy some more):<
#include<stdio.h>
char *d[16],y[]
Line 1,215 ⟶ 1,673:
'S',!(++u % 3) * 32+ 78) or
('.', puts("."))}return c;}
int main() {return p(0);}</
=={{header|C sharp|C#}}==
<
class Program
Line 1,393 ⟶ 1,704:
}
}
}</
=== C#6 Implementation ===
{{works with|C sharp|C#|6+}}
<
class Program
{
Line 1,407 ⟶ 1,718:
Console.WriteLine($"{f(i, true)}{f(i, false)}Take one down, pass it around\r\n{f(i - 1, true)}");
}
}</
=== Linq Implementation ===
{{works with|C sharp|C#|
<
using System.Linq;
Line 1,419 ⟶ 1,730:
static void Main()
{
$"{x} bottle{(x == 1 ? "" : "s")}
$"Take {(x == 1 ? "it" : "one")} down, pass it around, {(x == 1 ?
).ToList().ForEach(x => Console.WriteLine(x));
}
}</
=== Flexible Version ===
<
using System.Globalization;
class Program
Line 1,472 ⟶ 1,778:
}
}
}</
=== Using Formatting ===
{{works with|C sharp|C#|3+}}
<
{
static void Main(string[] args)
Line 1,504 ⟶ 1,810:
}
}
}</
{{out}}
Line 1,527 ⟶ 1,833:
{{works with|C sharp|C#|3+}}
<
using System.Linq;
Line 1,547 ⟶ 1,853:
yield return String.Format(f, booze(i, true), booze(i, false), booze(i - 1, true));
}
}</
=== A Fun One ===
<
"Abita Amber",
"Adams Broadside Ale",
Line 1,680 ⟶ 1,986:
Console.WriteLine();
Console.ReadLine();
}</
=== Using recursion ===
<
{
if (numberOfBottles > 0)
Line 1,694 ⟶ 2,000:
BottlesSong(--numberOfBottles);
}
}</
=== Using a While Loop ===
<
{
int numBottles = 99;
Line 1,717 ⟶ 2,023:
WriteLine("No more bottles of beer on the wall, no more bottles of beer.");
WriteLine("Go to the store to buy some more, 99 bottles of beer on the wall...");
}</
=={{header|C/vFP16}}==
<syntaxhighlight
lang="cpp">#pragma SCH_64_16_IFP
#import <jobsched.c>
__attr(@canschedule)
volatile constricts async UVOID <__INVAR const T>base_000000 __PCON(
impure VFCTX_t^ ct_base,
impure MCHR_t^ sched_arg,
__LVAR <const T>XVF_fntype_t^ f,
<out VF_QSWitch_t>XVF_fn_t^ switchctx
) __ARGFILL {
VF_Xsched_ILock(ct_base, $->sched);
captured __VFObj <>VF_KeDbg^ ki = VF_Xg_KeDbg_Instance();
captured deferred <__VF_T_Auto>__VF_Auto^ vfke = copyof VF_KeDbg_GetRstream<MCHR_t^>(captures ki);
VF_Gsched_SOBFree(sched_arg);
VF_Gsched_Alloc_U16(65535);
VF_Msched_MChr_lim(1496);
VF_Osched_Begin();
VF_Fsched_Add2(%beer_000099);
VF_Xsched_IUnlock(ct_base, $->sched);
$switchctx(IMPURE_CTX, %beer_000099(%vfke));
}
__attr(@eUsesIo)
impure constricts UVOID synchronized beer_000099(
impure __noinline <MCHR_t^>RIGHTSTREAM_t^ outrs
) __NFILL {
pure UVOID^ uvid = __attr(@purify) $UVOID.;
while ( 99 > ((volatile NUM_t)^(NUM_t^)(uvid))++ ) {
VF_STM_Out_NUM((NUM_t^)uvid);
VF_STM_Out_x(__Dynamic C"bottles on the wall.\nPut one down, pass it around\n");
}
return $__;
}
</syntaxhighlight>
=={{header|C++}}==
=== The simple solution ===
{{works with|g++|4.8.1}}
<syntaxhighlight lang="cpp">#include <iostream>
using std::cout;
int main()
{
for(int bottles(99); bottles > 0; bottles -= 1){
cout << bottles << " bottles of beer on the wall\n"
<< bottles << " bottles of beer\n"
<< "Take one down, pass it around\n"
<< bottles - 1 << " bottles of beer on the wall\n\n";
}
}</syntaxhighlight>
=== An object-oriented solution ===
See: [[99 Bottles of Beer/C++/Object Oriented]]
=== A template metaprogramming solution ===
Of course, the output of the program always looks the same. One may therefore question why the program has to do all that tedious subtracting during runtime. Couldn't the compiler just generate the code to output the text, with ready-calculated constants? Indeed, it can, and the technique is called template metaprogramming. The following short code gives the text without containing a single variable, let alone a loop:
<syntaxhighlight lang="cpp">#include <iostream>
template<int max, int min> struct bottle_countdown
{
static const int middle = (min + max)/2;
static void print()
{
bottle_countdown<max, middle+1>::print();
bottle_countdown<middle, min>::print();
}
};
template<int value> struct bottle_countdown<value, value>
{
static void print()
{
std::cout << value << " bottles of beer on the wall\n"
<< value << " bottles of beer\n"
<< "Take one down, pass it around\n"
<< value-1 << " bottles of beer\n\n";
}
};
int main()
{
bottle_countdown<100, 1>::print();
return 0;
}</syntaxhighlight>
=== A function template solution ===
Function templates are a different approach to template metaprogramming:
<syntaxhighlight lang="cpp">#include <iostream>
template<unsigned int N> void bottles(){
std::cout << N << " bottles of beer on the wall\n"
<< N << " bottles of beer\n"
<< "Take one down, pass it around\n"
<< N - 1 << " bottles of beer on the wall\n\n";
bottles<N-1>();
}
template<> void bottles<0>(){
std::cout<<"No more bottles of beer on the wall\n"
"No more bottles of beer\n"
"Go to the store and buy some more\n"
"99 bottles of beer on the wall...\n\n";
}
int main(){
bottles<99>();
}
</syntaxhighlight>
=== A Recursive solution ===
<syntaxhighlight lang="cpp">#include <iostream>
using namespace std;
void rec(int bottles)
{
if ( bottles!=0)
{
cout << bottles << " bottles of beer on the wall" << endl;
cout << bottles << " bottles of beer" << endl;
cout << "Take one down, pass it around" << endl;
cout << --bottles << " bottles of beer on the wall\n" << endl;
rec(bottles);
}
}
int main()
{
rec(99);
system("pause");
return 0;
}
</syntaxhighlight>
=== A preprocessor solution ===
Of course, with the template metaprogramming solution, the program has still do the conversion of numbers to strings at runtime, and those function calls also cost unnecessary time. Couldn't we just compose the complete text at compile time, and just output it at run time? Well, with the preprocessor, that's indeed possible:
<syntaxhighlight lang="cpp">#include <iostream>
#include <ostream>
#define BOTTLE(nstr) nstr " bottles of beer"
#define WALL(nstr) BOTTLE(nstr) " on the wall"
#define PART1(nstr) WALL(nstr) "\n" BOTTLE(nstr) \
"\nTake one down, pass it around\n"
#define PART2(nstr) WALL(nstr) "\n\n"
#define MIDDLE(nstr) PART2(nstr) PART1(nstr)
#define SONG PART1("100") CD2 PART2("0")
#define CD2 CD3("9") CD3("8") CD3("7") CD3("6") CD3("5") \
CD3("4") CD3("3") CD3("2") CD3("1") CD4("")
#define CD3(pre) CD4(pre) MIDDLE(pre "0")
#define CD4(pre) MIDDLE(pre "9") MIDDLE(pre "8") MIDDLE(pre "7") \
MIDDLE(pre "6") MIDDLE(pre "5") MIDDLE(pre "4") MIDDLE(pre "3") \
MIDDLE(pre "2") MIDDLE(pre "1")
int main()
{
std::cout << SONG;
return 0;
}</syntaxhighlight>
=== Bottled Version ===
<syntaxhighlight lang="cpp"> //>,_
//Beer Song>,_
#include <iostream>
using namespace std;
int main(){ for( int
b=-1; b<99; cout <<
'\n') for ( int w=0;
w<3; cout << ".\n"){
if (w==2) cout << ((
b--) ?"Take one dow"
"n and pass it arou"
"nd":"Go to the sto"
"re and buy some mo"
"re"); if (b<0) b=99
; do{ if (w) cout <<
", "; if (b) cout <<
b; else cout << (
(w) ? 'n' : 'N') <<
"o more"; cout <<
" bottle" ; if
(b!=1) cout <<
's' ; cout <<
" of beer";
if (w!=1)
cout <<
" on th"
"e wall"
;} while
(!w++);}
return
0
;
}
//
// by barrym 2011-05-01
// no bottles were harmed in the
// making of this program!!!</syntaxhighlight>
=={{header|Ceylon}}==
<
String bottles(Integer count) =>
Line 1,732 ⟶ 2,253:
``bottles(i - 1)`` of beer on the wall!\n");
}
}</
=={{header|Chapel}}==
copied from http://99-bottles-of-beer.net/language-chapel-1215.html, with minor modifications for chapel 1.7
{{works with|Chapel|1.7.0}}
<syntaxhighlight lang="chapel">
/***********************************************************************
* Chapel implementation of "99 bottles of beer"
Line 1,843 ⟶ 2,327:
else "Take one down and pass it around, ";
}
</syntaxhighlight>
=={{header|Chef}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|Cind}}==
<syntaxhighlight lang="cind">
execute() {
// this class provides synchronization
// to get unique number of the bottle
class monitor giver {
int number = 100;
.get() { return --number; }
}
var g = new giver();
// start 99 concurrently worked threads
// each thread gets own number of the bottle and prints out his own verse
// (notice that the output lines from the threads will be mixed together)
{#[99]
int nr = g.get(); // get own number
host.println(nr," bottles of beer on the wall, "+nr+" bottles of beer");
host.print("Take one down, pass it around,");
if (nr > 1) {
host.println((nr-1)," bottles of beer on the wall.");
}
else {
host.println("no more bottles of beer on the wall.");
}
}
host.println("No more bottles of beer on the wall, no more bottles of beer.");
host.println("Go to the store and buy some more, 99 bottles of beer on the wall.");
return 0;
}
</syntaxhighlight>
=={{header|Clay}}==
<syntaxhighlight lang="clay">/* A few options here: I could give n type Int; or specify that n is of any
numeric type; but here I just let it go -- that way it'll work with anything
that compares with 1 and that printTo knows how to convert to a string. And
all checked at compile time, remember. */
getRound(n) {
var s = String();
var bottle = if (n == 1) " bottle " else " bottles ";
printTo(s,
n, bottle, "of beer on the wall\n",
n, bottle, "of beer\n",
"take one down, pass it around\n",
n, bottle, "of beer on the wall!\n");
return s;
}
main() {
println(join("\n", mapped(getRound, reversed(range(100)))));
}
</syntaxhighlight>
=={{header|Clio}}==
<syntaxhighlight lang="clio">fn bottle n:
n -> if = 0: 'no more bottles'
elif = 1: n + ' bottle'
else: n + ' bottles'
[99:0] -> * (@eager) fn i:
i -> bottle -> print (transform i: sentence-case) 'of beer on the wall,' @ 'of beer.'
if i = 0:
'Go to the store, buy some more, 99 bottles of beer on the wall.' -> print
else:
i - 1 -> bottle -> print 'Take one down and pass it around,' @ 'of beer on the wall.\n'</syntaxhighlight>
=={{header|CLIPS}}==
<
(bottles 99))
Line 1,868 ⟶ 2,424:
(printout t "Take one down, pass it around," crlf)
(printout t (bottle-count (- ?count 1)) " on the wall." crlf crlf)
(if (> ?count 1) then (assert (bottles (- ?count 1)))))</
=={{header|Clojure}}==
<syntaxhighlight lang="clojure">(defn paragraph [num]
(str num " bottles of beer on the wall\n"
num " bottles of beer\n"
"Take one down, pass it around\n"
(defn lyrics []
(let [numbers (range 99 0 -1)
paragraphs (map paragraph numbers)]
(clojure.string/join "\n" paragraphs)))
(print (lyrics))</syntaxhighlight>
Or, using cl-format:
{{trans|Common Lisp}}
<
true
"~{~[~^~]~:*~D bottle~:P of beer on the wall~%~:*~D bottle~:P of beer
Take one down, pass it around,~%~D bottle~:P~:* of beer on the wall.~2%~}"
(range 99 0 -1))</
=={{header|CLU}}==
<syntaxhighlight lang="clu">bottles = proc (n: int) returns (string)
if n<0 then return("99 bottles")
elseif n=0 then return("No more bottles")
elseif n=1 then return("1 bottle")
else return(int$unparse(n) || " bottles")
end
end bottles
thirdline = proc (n: int) returns (string)
if n=0 then
return("Go to the store and buy some more,\n")
else
s: string
if n=1 then s := "it"
else s := "one"
end
return("Take " || s || " down and pass it around,\n");
end
end thirdline
verse = proc (n: int) returns (string)
v: string := bottles(n) || " bottles of beer on the wall,\n"
v := v || bottles(n) || " bottles of beer,\n"
v := v || thirdline(n)
v := v || bottles(n-1) || " bottles of beer on the wall.\n\n"
return(v)
end verse
start_up = proc ()
po: stream := stream$primary_output()
for n: int in int$from_to_by(99, 0, -1) do
stream$puts(po, verse(n))
end
end start_up</syntaxhighlight>
=={{header|COBOL}}==
{{works with|OpenCOBOL|1.1}}
Free form version.
<
program-id. ninety-nine.
environment division.
Line 1,998 ⟶ 2,592:
100-end.
end-program.</
Another free-form version, without using <code>DISPLAY NO ADVANCING</code>.
<
program-id. ninety-nine.
environment division.
Line 2,122 ⟶ 2,716:
100-end.
end-program.</
A more concise version that adheres to the minimum guidelines. Leading zeros are not suppressed. (OpenCOBOL - 1.1.0)
<
data division.
working-storage section.
Line 2,140 ⟶ 2,734:
add 1 to cnt
display space
end-perform.</
=={{header|CoffeeScript}}==
<
bottlesOfBeer = (n) ->
"#{n} bottle#{if n is 1 then '' else 's'} of beer"
Line 2,153 ⟶ 2,747:
#{bottlesOfBeer n - 1} on the wall
\n""" for n in [99..1]
</syntaxhighlight>
With completely different approach...
<
x=''
x += [j,j-1,'\nTake one down, pass it around\n'," bottles of beer",' on the wall\n'][i] for i in [0,3,4,0,3,2,1,3,4]
console.log x.replace /(1.+)s/g, '$1'
</syntaxhighlight>
or as a one liner...
<
or another completely different one liner
<
=={{header|ColdFusion}}==
=== Classic tag based CFML ===
<
<cfloop index="x" from="99" to="0" step="-1">
<cfset plur = iif(x is 1,"",DE("s"))>
Line 2,181 ⟶ 2,775:
#iif(x is 1,DE("No more"),"x-1")# bottle#iif(x is 2,"",DE("s"))# of beer on the wall<br><br>
</cfloop>
</cfoutput></
or if you prefer: (identical output, grammatically correct to the last stanza)
=== CFScript ===
<
for (x=99; x gte 1; x--) {
plur = iif(x==1,'',DE('s'));
WriteOutput("#x# bottle#plur# of beer on the wall<br>#x# bottle#plur# of beer<br>Take one down, pass it around<br>#iif(x is 1,DE('No more'),'x-1')# bottle#iif(x is 2,'',DE('s'))# of beer on the wall<br><br>");
}
</cfscript></
=={{header|Comal}}==
<syntaxhighlight lang="comal">0010 DIM itone$(0:1)
0020 itone$(0):="one";itone$(1):="it"
0030 FOR b#:=99 TO 1 STEP -1 DO
0040 bottles(b#)
0050 PRINT "of beer on the wall,"
0060 bottles(b#)
0070 PRINT "of beer,"
0080 PRINT "Take ",itone$(b#=1)," down and pass it around,"
0090 bottles(b#-1)
0100 PRINT "of beer on the wall!"
0110 PRINT
0120 ENDFOR b#
0130 PROC bottles(b#) CLOSED
0140 CASE b# OF
0150 WHEN 0
0160 PRINT "No more bottles ",
0170 WHEN 1
0180 PRINT "1 bottle ",
0190 OTHERWISE
0200 PRINT b#," bottles ",
0210 ENDCASE
0220 ENDPROC bottles
0230 END</syntaxhighlight>
=={{header|Comefrom0x10}}==
<
remaining = 99
one_less_bottle = remaining
Line 2,211 ⟶ 2,830:
comefrom if one_less_bottle is 0
'No more bottles of beer on the wall'</
{{out}}
Line 2,231 ⟶ 2,850:
=={{header|Component Pascal}}==
See [[99 Bottles of Beer/Pascal]]
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
sub Bottles(n: uint8) is
if n == 0 then
print("No more");
else
print_i8(n);
end if;
print(" bottle");
if n != 1 then
print("s");
end if;
end sub;
sub Verse(n: uint8) is
Bottles(n);
print(" of beer on the wall,\n");
Bottles(n);
print(" of beer,\n");
print("Take ");
if n == 1 then
print("it");
else
print("one");
end if;
print(" down and pass it around,\n");
Bottles(n-1);
print(" of beer on the wall.\n\n");
end sub;
var verse: uint8 := 99;
while verse > 0 loop
Verse(verse);
verse := verse - 1;
end loop;</syntaxhighlight>
{{out}}
<pre style='height: 50ex;'>99 bottles of beer on the wall,
99 bottles of beer,
Take one down and pass it around,
98 bottles of beer on the wall.
98 bottles of beer on the wall,
98 bottles of beer,
Take one down and pass it around,
97 bottles of beer on the wall.
97 bottles of beer on the wall,
97 bottles of beer,
Take one down and pass it around,
96 bottles of beer on the wall.
96 bottles of beer on the wall,
96 bottles of beer,
Take one down and pass it around,
95 bottles of beer on the wall.
95 bottles of beer on the wall,
95 bottles of beer,
Take one down and pass it around,
94 bottles of beer on the wall.
94 bottles of beer on the wall,
94 bottles of beer,
Take one down and pass it around,
93 bottles of beer on the wall.
93 bottles of beer on the wall,
93 bottles of beer,
Take one down and pass it around,
92 bottles of beer on the wall.
92 bottles of beer on the wall,
92 bottles of beer,
Take one down and pass it around,
91 bottles of beer on the wall.
91 bottles of beer on the wall,
91 bottles of beer,
Take one down and pass it around,
90 bottles of beer on the wall.
90 bottles of beer on the wall,
90 bottles of beer,
Take one down and pass it around,
89 bottles of beer on the wall.
89 bottles of beer on the wall,
89 bottles of beer,
Take one down and pass it around,
88 bottles of beer on the wall.
88 bottles of beer on the wall,
88 bottles of beer,
Take one down and pass it around,
87 bottles of beer on the wall.
87 bottles of beer on the wall,
87 bottles of beer,
Take one down and pass it around,
86 bottles of beer on the wall.
86 bottles of beer on the wall,
86 bottles of beer,
Take one down and pass it around,
85 bottles of beer on the wall.
85 bottles of beer on the wall,
85 bottles of beer,
Take one down and pass it around,
84 bottles of beer on the wall.
84 bottles of beer on the wall,
84 bottles of beer,
Take one down and pass it around,
83 bottles of beer on the wall.
83 bottles of beer on the wall,
83 bottles of beer,
Take one down and pass it around,
82 bottles of beer on the wall.
82 bottles of beer on the wall,
82 bottles of beer,
Take one down and pass it around,
81 bottles of beer on the wall.
81 bottles of beer on the wall,
81 bottles of beer,
Take one down and pass it around,
80 bottles of beer on the wall.
80 bottles of beer on the wall,
80 bottles of beer,
Take one down and pass it around,
79 bottles of beer on the wall.
79 bottles of beer on the wall,
79 bottles of beer,
Take one down and pass it around,
78 bottles of beer on the wall.
78 bottles of beer on the wall,
78 bottles of beer,
Take one down and pass it around,
77 bottles of beer on the wall.
77 bottles of beer on the wall,
77 bottles of beer,
Take one down and pass it around,
76 bottles of beer on the wall.
76 bottles of beer on the wall,
76 bottles of beer,
Take one down and pass it around,
75 bottles of beer on the wall.
75 bottles of beer on the wall,
75 bottles of beer,
Take one down and pass it around,
74 bottles of beer on the wall.
74 bottles of beer on the wall,
74 bottles of beer,
Take one down and pass it around,
73 bottles of beer on the wall.
73 bottles of beer on the wall,
73 bottles of beer,
Take one down and pass it around,
72 bottles of beer on the wall.
72 bottles of beer on the wall,
72 bottles of beer,
Take one down and pass it around,
71 bottles of beer on the wall.
71 bottles of beer on the wall,
71 bottles of beer,
Take one down and pass it around,
70 bottles of beer on the wall.
70 bottles of beer on the wall,
70 bottles of beer,
Take one down and pass it around,
69 bottles of beer on the wall.
69 bottles of beer on the wall,
69 bottles of beer,
Take one down and pass it around,
68 bottles of beer on the wall.
68 bottles of beer on the wall,
68 bottles of beer,
Take one down and pass it around,
67 bottles of beer on the wall.
67 bottles of beer on the wall,
67 bottles of beer,
Take one down and pass it around,
66 bottles of beer on the wall.
66 bottles of beer on the wall,
66 bottles of beer,
Take one down and pass it around,
65 bottles of beer on the wall.
65 bottles of beer on the wall,
65 bottles of beer,
Take one down and pass it around,
64 bottles of beer on the wall.
64 bottles of beer on the wall,
64 bottles of beer,
Take one down and pass it around,
63 bottles of beer on the wall.
63 bottles of beer on the wall,
63 bottles of beer,
Take one down and pass it around,
62 bottles of beer on the wall.
62 bottles of beer on the wall,
62 bottles of beer,
Take one down and pass it around,
61 bottles of beer on the wall.
61 bottles of beer on the wall,
61 bottles of beer,
Take one down and pass it around,
60 bottles of beer on the wall.
60 bottles of beer on the wall,
60 bottles of beer,
Take one down and pass it around,
59 bottles of beer on the wall.
59 bottles of beer on the wall,
59 bottles of beer,
Take one down and pass it around,
58 bottles of beer on the wall.
58 bottles of beer on the wall,
58 bottles of beer,
Take one down and pass it around,
57 bottles of beer on the wall.
57 bottles of beer on the wall,
57 bottles of beer,
Take one down and pass it around,
56 bottles of beer on the wall.
56 bottles of beer on the wall,
56 bottles of beer,
Take one down and pass it around,
55 bottles of beer on the wall.
55 bottles of beer on the wall,
55 bottles of beer,
Take one down and pass it around,
54 bottles of beer on the wall.
54 bottles of beer on the wall,
54 bottles of beer,
Take one down and pass it around,
53 bottles of beer on the wall.
53 bottles of beer on the wall,
53 bottles of beer,
Take one down and pass it around,
52 bottles of beer on the wall.
52 bottles of beer on the wall,
52 bottles of beer,
Take one down and pass it around,
51 bottles of beer on the wall.
51 bottles of beer on the wall,
51 bottles of beer,
Take one down and pass it around,
50 bottles of beer on the wall.
50 bottles of beer on the wall,
50 bottles of beer,
Take one down and pass it around,
49 bottles of beer on the wall.
49 bottles of beer on the wall,
49 bottles of beer,
Take one down and pass it around,
48 bottles of beer on the wall.
48 bottles of beer on the wall,
48 bottles of beer,
Take one down and pass it around,
47 bottles of beer on the wall.
47 bottles of beer on the wall,
47 bottles of beer,
Take one down and pass it around,
46 bottles of beer on the wall.
46 bottles of beer on the wall,
46 bottles of beer,
Take one down and pass it around,
45 bottles of beer on the wall.
45 bottles of beer on the wall,
45 bottles of beer,
Take one down and pass it around,
44 bottles of beer on the wall.
44 bottles of beer on the wall,
44 bottles of beer,
Take one down and pass it around,
43 bottles of beer on the wall.
43 bottles of beer on the wall,
43 bottles of beer,
Take one down and pass it around,
42 bottles of beer on the wall.
42 bottles of beer on the wall,
42 bottles of beer,
Take one down and pass it around,
41 bottles of beer on the wall.
41 bottles of beer on the wall,
41 bottles of beer,
Take one down and pass it around,
40 bottles of beer on the wall.
40 bottles of beer on the wall,
40 bottles of beer,
Take one down and pass it around,
39 bottles of beer on the wall.
39 bottles of beer on the wall,
39 bottles of beer,
Take one down and pass it around,
38 bottles of beer on the wall.
38 bottles of beer on the wall,
38 bottles of beer,
Take one down and pass it around,
37 bottles of beer on the wall.
37 bottles of beer on the wall,
37 bottles of beer,
Take one down and pass it around,
36 bottles of beer on the wall.
36 bottles of beer on the wall,
36 bottles of beer,
Take one down and pass it around,
35 bottles of beer on the wall.
35 bottles of beer on the wall,
35 bottles of beer,
Take one down and pass it around,
34 bottles of beer on the wall.
34 bottles of beer on the wall,
34 bottles of beer,
Take one down and pass it around,
33 bottles of beer on the wall.
33 bottles of beer on the wall,
33 bottles of beer,
Take one down and pass it around,
32 bottles of beer on the wall.
32 bottles of beer on the wall,
32 bottles of beer,
Take one down and pass it around,
31 bottles of beer on the wall.
31 bottles of beer on the wall,
31 bottles of beer,
Take one down and pass it around,
30 bottles of beer on the wall.
30 bottles of beer on the wall,
30 bottles of beer,
Take one down and pass it around,
29 bottles of beer on the wall.
29 bottles of beer on the wall,
29 bottles of beer,
Take one down and pass it around,
28 bottles of beer on the wall.
28 bottles of beer on the wall,
28 bottles of beer,
Take one down and pass it around,
27 bottles of beer on the wall.
27 bottles of beer on the wall,
27 bottles of beer,
Take one down and pass it around,
26 bottles of beer on the wall.
26 bottles of beer on the wall,
26 bottles of beer,
Take one down and pass it around,
25 bottles of beer on the wall.
25 bottles of beer on the wall,
25 bottles of beer,
Take one down and pass it around,
24 bottles of beer on the wall.
24 bottles of beer on the wall,
24 bottles of beer,
Take one down and pass it around,
23 bottles of beer on the wall.
23 bottles of beer on the wall,
23 bottles of beer,
Take one down and pass it around,
22 bottles of beer on the wall.
22 bottles of beer on the wall,
22 bottles of beer,
Take one down and pass it around,
21 bottles of beer on the wall.
21 bottles of beer on the wall,
21 bottles of beer,
Take one down and pass it around,
20 bottles of beer on the wall.
20 bottles of beer on the wall,
20 bottles of beer,
Take one down and pass it around,
19 bottles of beer on the wall.
19 bottles of beer on the wall,
19 bottles of beer,
Take one down and pass it around,
18 bottles of beer on the wall.
18 bottles of beer on the wall,
18 bottles of beer,
Take one down and pass it around,
17 bottles of beer on the wall.
17 bottles of beer on the wall,
17 bottles of beer,
Take one down and pass it around,
16 bottles of beer on the wall.
16 bottles of beer on the wall,
16 bottles of beer,
Take one down and pass it around,
15 bottles of beer on the wall.
15 bottles of beer on the wall,
15 bottles of beer,
Take one down and pass it around,
14 bottles of beer on the wall.
14 bottles of beer on the wall,
14 bottles of beer,
Take one down and pass it around,
13 bottles of beer on the wall.
13 bottles of beer on the wall,
13 bottles of beer,
Take one down and pass it around,
12 bottles of beer on the wall.
12 bottles of beer on the wall,
12 bottles of beer,
Take one down and pass it around,
11 bottles of beer on the wall.
11 bottles of beer on the wall,
11 bottles of beer,
Take one down and pass it around,
10 bottles of beer on the wall.
10 bottles of beer on the wall,
10 bottles of beer,
Take one down and pass it around,
9 bottles of beer on the wall.
9 bottles of beer on the wall,
9 bottles of beer,
Take one down and pass it around,
8 bottles of beer on the wall.
8 bottles of beer on the wall,
8 bottles of beer,
Take one down and pass it around,
7 bottles of beer on the wall.
7 bottles of beer on the wall,
7 bottles of beer,
Take one down and pass it around,
6 bottles of beer on the wall.
6 bottles of beer on the wall,
6 bottles of beer,
Take one down and pass it around,
5 bottles of beer on the wall.
5 bottles of beer on the wall,
5 bottles of beer,
Take one down and pass it around,
4 bottles of beer on the wall.
4 bottles of beer on the wall,
4 bottles of beer,
Take one down and pass it around,
3 bottles of beer on the wall.
3 bottles of beer on the wall,
3 bottles of beer,
Take one down and pass it around,
2 bottles of beer on the wall.
2 bottles of beer on the wall,
2 bottles of beer,
Take one down and pass it around,
1 bottle of beer on the wall.
1 bottle of beer on the wall,
1 bottle of beer,
Take it down and pass it around,
No more bottles of beer on the wall.</pre>
=={{header|Crystal}}==
<
puts "#{n} bottle#{n > 1 ? "s" : ""} of beer on the wall"
puts "#{n} bottle#{n > 1 ? "s" : ""} of beer"
Line 2,240 ⟶ 3,394:
end
puts "No more bottles of beer on the wall"
</syntaxhighlight>
=={{header|D}}==
Line 2,249 ⟶ 3,403:
Based on Steward Gordon's code at: [http://99-bottles-of-beer.net/language-d-721.html 99-bottles-of-beer.net].
<
void main() {
Line 2,268 ⟶ 3,422:
writeln("Go to the store and buy some more,");
writeln("99 bottles of beer on the wall.");
}</
=== CTFE Solution ===
Line 2,274 ⟶ 3,428:
CTFE (Compile-Time Function Execution) is a feature of D that allows for pure functions of arbitrary complexity to be completely evaluated at compile time when every parameter is known. Note that this is distinct from the template meta-programming tricks used by some other languages, and this bottles() function could just as easily be executed during run-time. The compiled result of this program simply prints the pre-generated lyrics to the song, using a standard compiler pragma directive.
<
string bottles(in size_t num) pure {
Line 2,297 ⟶ 3,451:
pragma(msg, 99.bottles);
void main() {}</
=== Template Meta-Programming Solution ===
Line 2,303 ⟶ 3,457:
Uses D template meta-programming and recursion to pre-generate the song lyrics and prints it at compile via pragma(msg,...)
<syntaxhighlight lang="d">
module bottles;
Line 2,325 ⟶ 3,479:
void main(){}
</syntaxhighlight>
=={{header|Dart}}==
// Making use of polymorphism
<syntaxhighlight lang="dart">main() {
BeerSong beerSong = BeerSong();
//pass a 'starting point' and 'end point' as parameters respectively
String printTheLyrics = beerSong.recite(99, 1).join('\n');
}
class Song {
String bottleOnTheWall(int index) {
String bottleOnTheWallText =
'$index bottles of beer on the wall, $index bottles of beer,';
return bottleOnTheWallText;
}
String bottleTakenDown(int index) {
String englishGrammar = (index >= 2) ? 'bottle' : 'bottles';
String bottleTakenDownText =
'Take one down and pass it around, ${index - 1} $englishGrammar of beer on the wall.';
return bottleTakenDownText;
}
}
class BeerSong extends Song {
@override
String bottleOnTheWall(int index) {
String originalText = super.bottleOnTheWall(index);
if (index < 2) {
String bottleOnTheWallText =
'$index bottle of beer on the wall, $index bottle of beer,';
return bottleOnTheWallText;
}
return originalText;
}
@override
String bottleTakenDown(int index) {
if (index < 2) {
String bottleTakenDownText =
'Take it down and pass it around, no more bottles of beer on the wall.';
return bottleTakenDownText;
}
String originalText = super.bottleTakenDown(index);
return originalText;
}
List<String> recite(int actualBottleOnTheWall, int remainingBottleOnTheWall) {
List<String> theLyrics = [];
for (int index = actualBottleOnTheWall;
index >= remainingBottleOnTheWall;
index--) {
String onTheWall = bottleOnTheWall(index);
String takenDown = bottleTakenDown(index);
theLyrics.add(onTheWall);
theLyrics.add(takenDown);
theLyrics.add('');
}
return theLyrics;
}
}
}</syntaxhighlight>
=={{header|Dc}}==
Line 2,342 ⟶ 3,549:
{{works with|GNU dc}}
{{works with|OpenBSD dc}}
<syntaxhighlight lang="dc">[
dnrpr
dnlBP
Line 2,370 ⟶ 3,577:
]P
[no more bottles of beer on the wall
]P</
Similar to the program above, but without 'n' and 'r' commands. It prints the numbers on separate lines than the strings.
{{works with|AT&T dc}}
<syntaxhighlight lang="dc">[
plAP
plBP
Line 2,406 ⟶ 3,613:
]P
[no more bottles of beer on the wall
]P</
=={{header|DBL}}==
<syntaxhighlight lang="text">;
;===============================================================================
; Oringinal Author: Bob Welton (welton@pui.com)
; Language: DIBOL or DBL
;
; Modified to work with DBL version 4
; by Dario B.
;===============================================================================
RECORD
NRBOT,D2,99 ;Default # of bottles to 99
A2, A2
PROC
;-------------------------------------------------------------------------------
XCALL FLAGS (0007000000,1) ;Suppress STOP message
OPEN (1,O,"TT:") ;Open the terminal/display
DO FOREVER
BEGIN
A2=NRBOT,'ZX'
DISPLAY (1,A2," Bottles of Beer on the wall,",10)
A2=NRBOT,'ZX'
DISPLAY (1,A2," Bottles of Beer,",10)
DISPLAY (1," Take one down, pass it around,",10)
DECR NRBOT ;Reduce # of bottles by 1
IF (NRBOT.LE.1) EXITLOOP ;If just 1 bottle left, get out
A2=NRBOT,'ZX'
DISPLAY (1,A2," Bottles of Beer on the wall.",10,10)
END
A2=NRBOT,'ZX'
DISPLAY (1,A2," Bottle of Beer on the wall,",10,10)
A2=NRBOT,'ZX'
DISPLAY (1,A2," Bottle of Beer,",10)
DISPLAY (1," Take one down, pass it around,",10)
DISPLAY (1,"0 Bottles of Beer on the wall,",10)
DISPLAY (1,"0 Bottles of Beer,",10)
DISPLAY (1,"Go to the store and buy some more,",10)
DISPLAY (1,"99 Bottles of Beer on the wall,",10,10,10)
CLOSE 1
STOP</syntaxhighlight>
=={{header|Delphi}}==
See [[99 Bottles of Beer/Pascal]]
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec bottles(byte b) void:
if b=0 then write("No more") else write(b) fi;
write(" bottle");
if b~=1 then write("s") fi
corp;
proc nonrec verse(byte v) void:
bottles(v);
writeln(" of beer on the wall,");
bottles(v);
writeln(" of beer,");
writeln("Take ",
if v=1 then "it" else "one" fi,
" down and pass it around");
bottles(v-1);
writeln(" of beer on the wall!\n");
corp;
proc nonrec main() void:
byte v;
for v from 99 downto 1 do verse(v) od
corp</syntaxhighlight>
=={{header|Dyalect}}==
{{trans|Swift}}
<syntaxhighlight lang="dyalect">for i in 99^-1..1 {
print("\(i) bottles of beer on the wall, \(i) bottles of beer.")
let next = i is 1 ? "no" : i - 1
print("Take one down and pass it around, \(next) bottles of beer on the wall.")
}</syntaxhighlight>
=={{header|Dylan}}==
<syntaxhighlight lang="dylan">Module: bottles
define method bottles (n :: <integer>)
for (n from 99 to 1 by -1)
format-out("%d bottles of beer on the wall,\n"
"%d bottles of beer\n"
"Take one down, pass it around\n"
"%d bottles of beer on the wall\n",
n, n, n - 1);
end
end method</syntaxhighlight>
=={{header|Déjà Vu}}==
<
if = 1 i "" "s"
Line 2,428 ⟶ 3,733:
!print "Go to the store and buy some more, 99 bottles of beer on the wall."
bottles 99</
=={{header|
<syntaxhighlight lang="dibol-11">
;
;===============================================================================
========================
; Oringinal Author: Bob Welton (welton@pui.com)
; Language: DIBOL or DBL
;
; Modified to work with DEC DIBOL-11
; by Bill Gunshannon
;===============================================================================
========================
RECORD MISC
NUMBOTTLES ,D2,99 ;Default # of bottles to 99
RECORD LINE1
ANUMBOTTLES, A2
, A32, " Bottles of Beer on the wall,"
RECORD LINE2
BNUMBOTTLES, A2
, A32, " Bottles of Beer,"
RECORD LINE3
CNUMBOTTLES, A2
, A32, " Bottles of Beer on the wall."
RECORD LINE4
DNUMBOTTLES, A2
, A32, " Bottle of Beer on the wall,"
RECORD LINE5
ENUMBOTTLES, A2
, A32, " Bottle of Beer,"
.PROC
XCALL FLAGS (0007000000,1) ;Suppress STOP message
OPEN (8,O:C,"TT:") ;Open the terminal/display
REPEAT
BEGIN
ANUMBOTTLES = NUMBOTTLES,'ZX'
WRITES (8,LINE1)
BNUMBOTTLES = NUMBOTTLES,'ZX'
WRITES (8,LINE2)
WRITES (8," Take one down, pass it around,")
DECR NUMBOTTLES ;Reduce # of bottles by 1
IF (NUMBOTTLES .LE. 1) EXITLOOP ;If just 1 bottle left, get out
CNUMBOTTLES = NUMBOTTLES,'ZX'
WRITES (8,LINE3)
WRITES (8," ")
END
DNUMBOTTLES = NUMBOTTLES,'ZX'
WRITES(8,LINE4)
WRITES (8," ")
ENUMBOTTLES = NUMBOTTLES,'ZX'
WRITES(8,LINE5)
WRITES (8," Take one down, pass it around,")
WRITES(8,"0 Bottles of Beer on the wall,")
WRITES(8,"0 Bottles of Beer,")
WRITES(8,"Go to the store and buy some more,")
WRITES(8,"99 Bottles of Beer on the wall,")
WRITES (8," ")
WRITES (8," ")
SLEEP 2
CLOSE 8
STOP
.END
</syntaxhighlight>
=={{header|E}}==
<
return switch (n) {
match ==0 { "No bottles" }
Line 2,468 ⟶ 3,825:
${bottles(n.previous())} of beer on the wall.
`)
}</
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func$ bottle num .
if num = 1
return "bottle"
.
return "bottles"
.
#
i = 99
repeat
print i & " " & bottle i & " of beer on the wall"
print i & " " & bottle i & " of beer"
print "Take one down, pass it around"
i -= 1
until i = 0
print i & " " & bottle i & " of beer on the wall"
print ""
.
print "No more bottles of beer on the wall"
</syntaxhighlight>
=={{header|ECL}}==
<syntaxhighlight lang="ecl">
Layout := RECORD
UNSIGNED1 RecID1;
Line 2,494 ⟶ 3,873:
Rev := NORMALIZE(Beers,5,XF(LEFT,COUNTER));
OUTPUT(SORT(Rev,-Recid1,-RecID2),{txt},ALL);
</syntaxhighlight>
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">module Bottles {
void run() {
function String(Int) num = i -> i==0 ? "No" : i.toString();
function String(Int) bottles = i -> i==1 ? "bottle" : "bottles";
@Inject Console console;
for (Int remain : 99..1) {
console.print($|{num(remain)} {bottles(remain)} of beer on the wall
|{num(remain)} {bottles(remain)} of beer
|Take one down, pass it around
|{num(remain-1)} {bottles(remain-1)} of beer on the wall
|
);
}
}
}</syntaxhighlight>
=={{header|Egel}}==
<syntaxhighlight lang="egel">
import "prelude.eg"
import "io.ego"
Line 2,514 ⟶ 3,911:
def main = print_rhyme 99
</syntaxhighlight>
=={{header|EGL}}==
<
function main()
Line 2,538 ⟶ 3,935:
end
end
end</
=={{header|Eiffel}}==
<
class
APPLICATION
Line 2,582 ⟶ 3,979:
end
</syntaxhighlight>
An alternative version written using the across-loop construct.
<
output_lyrics
-- Output the lyrics to 99-bottles-of-beer.
Line 2,609 ⟶ 4,006:
end
</syntaxhighlight>
=={{header|Ela}}==
<
beer 1 = "1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around"
Line 2,621 ⟶ 4,018:
++" bottles of beer\nTake one down, pass it around\n"
map beer [99,98..0]</
=={{header|Elan}}==
<syntaxhighlight lang="elan">INT VAR number of bottles;
PROCEDURE print how many bottles are on the wall (INT CONST number):
print number;
print bottle;
print trailing text.
print number:
IF number = 0 THEN
put ("No")
ELSE
put (number)
END IF.
print bottle:
out ("Bottle");
IF no <> 1 THEN
out ("s")
END IF.
print trailing text:
out (" of beer").
END PROCEDURE print how many bottles are on the wall;
say hello;
print song;
say goodbye.
say hello:
putline ("99 Bottles of Beer");
putline ("==================");
line.
print song:
FOR number of bottles FROM 99 DOWNTO 1 REPEAT
print first line;
print second line;
print third line
END REPEAT.
say goodbye:
line;
putline ("=====================");
putline ("You need a ride home?");
line.
print first line:
print how many bottles are on the wall (number of bottles);
out (" on the wall, ");
print how many bottles are on the wall (number of bottles);
line.
print second line:
putline ("Take one down and pass it around,").
print third line:
print how many bottles are on the wall (number of bottles - 1);
putline (" on the wall");
line.</syntaxhighlight>
=={{header|Elena}}==
ELENA
<
import extensions;
import extensions'routines;
Line 2,633 ⟶ 4,091:
{
bottleDescription()
= self.
bottleEnumerator() = new Variable(self).doWith::(n)
{
^ new Enumerator
{
bool next() = n > 0;
get Value() = new StringWriter()
.printLine(n.bottleDescription()," of beer on the wall")
.printLine(n.bottleDescription()," of beer")
.printLine("Take one down, pass it around")
.printLine((n.reduce
reset() {}
enumerable() =
}
};
Line 2,658 ⟶ 4,116:
var bottles := 99;
bottles.bottleEnumerator().forEach
}</
{{out}}
<pre>
Line 2,687 ⟶ 4,145:
0 bottles of beer on the wall
</pre>
=={{header|Elixir}}==
<
def run do
Enum.each 99..1, fn idx ->
Line 2,710 ⟶ 4,162:
end
Bottles.run</
=={{header|Elm}}==
<syntaxhighlight lang="elm">module Main exposing (main)
import Html
main =
List.range 1 100
|> List.reverse
|> List.map
(\n ->
let
nString =
String.fromInt n
n1String =
String.fromInt (n - 1)
in
[ nString ++ " bottles of beer on the wall"
, nString ++ " bottles of beer"
, "Take one down, pass it around"
, n1String ++ " bottles of beer on the wall"
]
|> List.map Html.text
|> List.intersperse (Html.br [] [])
|> Html.p []
)
|> Html.div []</syntaxhighlight>
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(let ((i 99))
(while (> i 0)
(message "%d bottles of beer on the wall" i)
(message "%d bottles of beer" i)
(message "Take one down, pass it around")
(message "%d bottles of beer on the wall" (1- i))
(setq i (1- i))))</syntaxhighlight>
=={{header|EMal}}==
This version writes the lyrics as described here: https://99-bottles-of-beer.net/lyrics.html
<syntaxhighlight lang="emal">
type NinetynineBottles
int DEFAULT_BOTTLES_COUNT = 99
model
int initialBottlesCount, bottlesCount
new by int =bottlesCount
me.initialBottlesCount = bottlesCount
end
fun subject = <|when(me.bottlesCount == 1, "bottle", "bottles")
fun bottles = <|when(me.bottlesCount == 0, "no more", text!me.bottlesCount)
fun goToWall = void by block
text line = me.bottles() + " " + me.subject() + " of beer on the wall, " +
me.bottles() + " " + me.subject() + " of beer."
if me.bottlesCount == 0 do line[0] = line[0].upper() end # text can be modified
writeLine(line)
end
fun takeOne = logic by block
if --me.bottlesCount < 0 do return false end # cannot take a beer down
writeLine("Take one down and pass it around, " + me.bottles() +
" " + me.subject() + " of beer on the wall.")
writeLine()
return true
end
fun goToStore = void by block
writeLine("Go to the store and buy some more, " + me.initialBottlesCount +
" bottles of beer on the wall.")
end
fun play = void by block
for ever
me.goToWall()
if not me.takeOne()
me.goToStore()
break
end
end
end
end
NinetynineBottles(when(Runtime.args.length > 0, int!Runtime.args[0], DEFAULT_BOTTLES_COUNT)).play()
</syntaxhighlight>
The output for two bottles of beer is as follows.
{{out}}
<pre>
2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.
1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.
No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 2 bottles of beer on the wall.
</pre>
=={{header|Erlang}}==
<
-export([sing/0]).
-define(TEMPLATE_0, "~s of beer on the wall, ~s of beer.~nGo to the store and buy some more, 99
Line 2,751 ⟶ 4,295:
spawn_singer(Bottle),
sing_verse(Bottle)
end.</
=={{header|Euphoria}}==
{{works with|Euphoria|4.0.0}}
<syntaxhighlight lang="euphoria">constant
bottles = "bottles",
bottle = "bottle"
Line 2,783 ⟶ 4,326:
for a = 99 to 1 by -1 do
beers (a)
end for</syntaxhighlight>
<syntaxhighlight lang="euphoria">-- An alternate version
include std/console.e
sequence howmany = {"No more bottles","%d bottle","","s"}
for beer = 99 to 1 by -1 do
display(`
[1] bottles of beer on the wall,
[1] bottles of beer.
Take one down, drink it right down,
[2][3] of beer.
`,{beer,
sprintf(howmany[(beer>1)+1],beer-1),
howmany[(beer>2)+3]
})
end for</syntaxhighlight>
<syntaxhighlight lang="euphoria">-- yet another version:
include std/console.e
object stanza = {
"[] bottles of beer on the wall,",
"[] bottles of beer,",
"take one down, and pass it around,"
}
object bottles = 99
loop do
display(stanza[1],bottles)
display(stanza[2],bottles)
display(stanza[3])
bottles -= 1
display(stanza[1]&"\n",{bottles})
until bottles = 0
end loop</syntaxhighlight>
=={{header|Extended BrainF***}}==
Line 2,790 ⟶ 4,371:
=={{header|F_Sharp|F#}}==
<
let rec bottles n =
let (before, after) = match n with
Line 2,801 ⟶ 4,382:
printfn "%d %s of beer on the wall\n" (n - 1) after
if n > 1 then
bottles (n - 1)</
=={{header|Factor}}==
<
: bottle ( -- quot )
Line 2,825 ⟶ 4,406:
1 [a,b] bottle each last-verse ;
! Usage: 99 bottles</
=={{header|Falcon}}==
<
> i, " bottles of beer on the wall"
> i, " bottles of beer"
> "Take one down, pass it around"
> i-1, " bottles of beer on the wall\n"
end</
A more robust version to handle plural/not plural conditions
<
plural = (i != 1) ? 's' : ""
> @ "$i bottle$plural of beer on the wall"
Line 2,842 ⟶ 4,423:
> "Take one down, pass it around"
> i-1, @ " bottle$plural of beer on the wall\n"
end</
=={{header|FALSE}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|Fe}}==
<syntaxhighlight lang="clojure">
(= n 99)
(while (< 0 n)
(print n "bottles of beer on the wall")
(print n "bottles of beer")
(print "Take one down, pass it around")
(= n (- n 1))
(print n "bottles of beer on the wall\n"))
</syntaxhighlight>
=={{header|ferite}}==
copied from [http://99-bottles-of-beer.net/language-ferite-1281.html?PHPSESSID=b563ec9a2791f6c3cc917c22b17dc542 99-bottles-of-beer.net].
<
number bottles = 99;
Line 2,869 ⟶ 4,461:
looping = counter.invoke();
Console.println("${bottles} bottles of beer on the wall.");</
=={{header|Fexl}}==
<
\suffix=(\n eq n 1 "" "s")
\sing_count=(\n put [n " bottle" (suffix n) " of beer"])
Line 2,889 ⟶ 4,481:
)
sing 3
</syntaxhighlight>
{{out}}
Line 2,909 ⟶ 4,501:
</pre>
=={{header|FOCAL}}==
<syntaxhighlight lang="focal">01.10 S N=99
01.15 D 2;T " OF BEER ON THE WALL,",!
01.20 D 2;T " OF BEER,",!
01.24 S N=N-1
01.25 T "TAKE ";I (N),1.3,1.4,1.3
01.30 T "IT";G 1.5
01.40 T "ONE"
01.50 T " DOWN AND PASS IT AROUND,",!
01.60 D 2;T " OF BEER ON THE WALL!",!!
01.70 I (N),1.8,1.15
01.80 Q
02.01 C-PRINT N BOTTLE(S)
02.10 I (N)2.2,2.2,2.3
02.20 T "NO MORE";G 2.4
02.30 D 3
02.40 T " BOTTLE";I (N-1)2.5,2.6,2.5
02.50 T "S"
02.60 R
03.01 C-PRINT 2-DIGIT NUMBER IN N
03.02 C-THIS IS NECESSARY BECAUSE T ALWAYS PREPENDS = TO NUMBERS
03.10 S A=FITR(N/10);I (A),3.3,3.2
03.20 D 4
03.30 S A=N-FITR(N/10)*10;D 4
04.01 C-PRINT DIGIT IN A
04.10 I (A-0),4.20,4.11
04.11 I (A-1),4.21,4.12
04.12 I (A-2),4.22,4.13
04.13 I (A-3),4.23,4.14
04.14 I (A-4),4.24,4.15
04.15 I (A-5),4.25,4.16
04.16 I (A-6),4.26,4.17
04.17 I (A-7),4.27,4.18
04.18 I (A-8),4.28,4.19
04.19 T "9";R
04.20 T "0";R
04.21 T "1";R
04.22 T "2";R
04.23 T "3";R
04.24 T "4";R
04.25 T "5";R
04.26 T "6";R
04.27 T "7";R
04.28 T "8";R</syntaxhighlight>
=={{header|Forth}}==
<
:noname ." 1 bottle" ;
:noname ." no more bottles" ;
Line 2,924 ⟶ 4,564:
: verses begin cr .verse ?dup 0= until ;
99 verses</
Version 2: create a beer language and write the program
<
: BOTTLES ( n -- )
DUP
Line 2,961 ⟶ 4,601:
ONELESS BOTTLES OF BEER ON THE WALL .
ANOTHER
HANGOVER ;</
Forth Console Output
<
2 bottles of beer on the wall,
2 bottles of beer ,
Line 2,975 ⟶ 4,615:
No more bottles of beer on the wall.
ok</
=={{header|Fortran}}==
===F90 version===
<
implicit none
Line 3,002 ⟶ 4,642:
end do
end program bottlestest</
===MPI version===
<
implicit none
Line 3,032 ⟶ 4,672:
call mpi_finalize(ierr)
end program bottlesMPI</
Usage:
Line 3,040 ⟶ 4,680:
===Fortran 2003/2008 OOP version===
Works with GNU gfortran 5.0.0 and Intel ifort 15.0.2
<
module song_typedefs
implicit none
Line 3,173 ⟶ 4,813:
end program bottles_song
</syntaxhighlight>
=={{header|Frege}}==
Line 3,180 ⟶ 4,820:
{{Works with|Frege|3.21.586-g026e8d7}}
<
main = mapM_ (putStrLn . beer) [99, 98 .. 0]
Line 3,188 ⟶ 4,828:
++ show v
++ " bottles of beer\nTake one down, pass it around\n"
++ head (lines $ beer $ v-1) ++ "\n"</
=={{header|friendly interactive shell}}==
Line 3,195 ⟶ 4,835:
=={{header|Frink}}==
Frink tracks units of measure through all calculations. It has a large library of built-in units of measure, including volume. The following program prints out the remaining volume of beer (assuming we start with 99 bottles of beer, each containing 12 fluid ounces) in different random units of volume, never repeating a unit.
<
units = array[units[volume]]
showApproximations[false]
Line 3,213 ⟶ 4,853:
getBottleString[n, unit] := format[n*12 floz, unit, 6] + "s"
</syntaxhighlight>
Sample randomized output:
Line 3,252 ⟶ 4,892:
=={{header|FunL}}==
<
numbers = {1:'one', 2:'two', 3:'three', 4:'four', 5:'five', 6:'six', 7:'seven',
8:'eight', 9:'nine', 10:'ten', 11:'eleven', 12:'twelve'}
Line 3,281 ⟶ 4,921:
+ ' of beer on the wall.\n')
for i <- 99..0 by -1 do println( verse(i) )</
=={{header|FutureBasic}}==
<
include "
NSUInteger i
CFStringRef a, b, c
a = @" bottles of beer on the wall,\n"
b = @" bottles of beer.\n"
c = @"Take one down, pass it around,\n"
for i = 99 to 1 step -1
NSLog( @"%ld%@%ld%@%@%ld%@\n", i, a, i, b, c, i -1, a )
next
HandleEvents
</syntaxhighlight>
=={{header|Gambas}}==
Implementation of the code '99 bottles of beer' written in Visual Basic. Code tested in Gambas 3.15.2
<syntaxhighlight lang="gambas">' Gambas module file
Public Const bottlesofbeer As String = " bottles of beer."
Public Const onthewall As String = " on the wall."
Public Const takeonedown As String = "Take one down, pass it around."
Public Const onebeer As String = "1 bottle of beer"
Public Sub Main()
Dim bottles As Byte
For bottles = 99 To 3 Step -1
Print CStr(bottles) & bottlesofbeer & onthewall
Print CStr(bottles) & bottlesofbeer
Print takeonedown
Print CStr(bottles - 1) & bottlesofbeer & onthewall
Print
Next
Print "2" & bottlesofbeer & onthewall
Print "2" & bottlesofbeer
Print takeonedown
Print onebeer & onthewall
Print
Print onebeer & onthewall
Print onebeer
Print takeonedown
Print "No more" & bottlesofbeer & onthewall
Print
Print "No" & bottlesofbeer & onthewall
Print "No" & bottlesofbeer
Print "Go to the store, buy some more."
Print "99" & bottlesofbeer & onthewall
End</syntaxhighlight>
=={{header|GAP}}==
<
local line, i, j, u;
line := function(n)
Line 3,322 ⟶ 5,004:
fi;
od;
end;</
=={{header|GDScript}}==
{{works with|Godot|4.0}}
<syntaxhighlight lang="gdscript">
extends MainLoop
# Represents a count of bottles
class Bottles:
var count := 99
func take(n: int = 1) -> void:
count -= n
func _to_string() -> String:
match count:
0: return "No more bottles"
1: return "1 bottle"
_: return "%s bottles" % count
func _process(_delta: float) -> bool:
var bottles := Bottles.new()
while bottles.count > 0:
print("%s of beer on the wall" % bottles)
print("%s of beer" % bottles)
print("Take one down, pass it around")
bottles.take()
print("%s of beer on the wall" % bottles)
# Seperate paragraphs
if bottles.count > 0:
print()
return true # Makes the program exit
</syntaxhighlight>
===Silly node-tree version===
This uses the node's children as the display method (which can be viewed in-editor with the remote tab).
<syntaxhighlight lang="gdscript">
extends Node
@export var alcoholism: int = 99
func _ready():
# Add the lyrics as child nodes
var padding := "" # Avoid name clashes by adding spaces
for bottleCount in range(alcoholism, 0, -1):
# Seperate paragraphs with blank nodes
if bottleCount < alcoholism:
add_lyric(padding)
add_lyric("%s of beer on the wall" % [_formatBottles(bottleCount)])
add_lyric("%s of beer" % [_formatBottles(bottleCount)])
add_lyric("Take one down, pass it around" + padding)
add_lyric("%s of beer on the wall " % [_formatBottles(bottleCount - 1)]) # Extra space for name clash avoidance
padding += " " # Add spaces so the names don't clash
func _formatBottles(bottleCount: int) -> String:
return "%d bottle%s" % [bottleCount, "" if bottleCount == 1 else "s"]
func add_lyric(lyric: String) -> void:
var new_child := Node.new()
new_child.name = lyric
add_child(new_child)
</syntaxhighlight>
=={{header|Genie}}==
<
def plural(n:uint):string
return (n == 1) ? "" : "s"
Line 3,331 ⟶ 5,077:
return (n == 0) ? "No" : n.to_string()
init
bottles:uint =
do
print "%u bottle%s of beer on the wall", bottles, plural(bottles)
Line 3,338 ⟶ 5,084:
--bottles
print "%s bottle%s of beer on the wall\n", no(bottles), plural(bottles)
while bottles != 0</
{{out}}
Line 3,354 ⟶ 5,100:
=={{header|gnuplot}}==
<
print sprintf("%i bottles of beer on the wall", bottles)
print sprintf("%i bottles of beer", bottles)
Line 3,361 ⟶ 5,107:
print sprintf("%i bottles of beer on the wall", bottles)
print ""
if (bottles > 0) reread</
=={{header|Go}}==
===No sense of humor===
<
import "fmt"
Line 3,387 ⟶ 5,133:
fmt.Printf("%s of beer on the wall\n", bottles(i-1))
}
}</
===Typoglycemic===
With code from RC tasks Number names, Knuth shuffle.
<
import (
Line 3,470 ⟶ 5,216:
w := strings.Fields(p[:1] + string(a) + p[len(p)-1:])
return strings.Join(w, " ")
}</
{{out}}
Things start out pretty well...
Line 3,512 ⟶ 5,258:
=={{header|Go!}}==
Copied from [http://99-bottles-of-beer.net/language-go!-289.html The 99 Bottles of Beer web site] with a minor bug fix.
<
-- 99 Bottles of Beer in Go!
-- John Knottenbelt
Line 3,542 ⟶ 5,288:
bottles(1) => "1 bottle of beer".
bottles(i) => i^0 <> " bottles of beer".
}</
=={{header|Golfscript}}==
<syntaxhighlight lang="golfscript">[296,{3/)}%-1%["No more"]+[" bottles":b]294*[b-1<]2*+[b]+[" of beer on the wall\n".8<"\nTake one down, pass it around\n"+1$n+]99*]zip</syntaxhighlight>
=={{header|Golo}}==
<syntaxhighlight lang="golo">module Bottles
augment java.lang.Integer {
function bottles = |self| -> match {
when self == 0 then "No bottles"
when self == 1 then "One bottle"
otherwise self + " bottles"
}
}
function main = |args| {
99: downTo(1, |i| {
println(i: bottles() + " of beer on the wall,")
println(i: bottles() + " of beer!")
println("Take one down, pass it around,")
println((i - 1): bottles() + " of beer on the wall!")
println("--------------------------------------")
})
}</syntaxhighlight>
=={{header|Gosu}}==
<
for (i in 99..0) {
Line 3,557 ⟶ 5,327:
}
</syntaxhighlight>
=={{header|Groovy}}==
===Basic Solution===
With a closure to handle special cardinalities of bottles.
<
99.downto(1) { i ->
Line 3,574 ⟶ 5,341:
${bottles(i-1)} of beer on the wall
"""
}</
=== Single Print Version ===
Uses a single print algorithm for all four lines. Handles cardinality on bottles, uses 'No more' instead of 0.
<
def (m,d) = [it%3,(int)it/3]
print "${m==1?'\n':''}${d?:'No more'} bottle${d!=1?'s':''} of beer" +
"${m?' on the wall':'\nTake one down, pass it around'}\n"
}</
===Bottomless Beer Solution===
Using more closures to create a richer lyrical experience.
<
def initialState = {
Line 3,615 ⟶ 5,382:
}
// Thread.sleep(1000)
// }</
=={{header|GUISS}}==
Line 3,621 ⟶ 5,388:
We will just use the calculator and keep taking one off. We do not get the full text here, but the number of the calculator shows how many bottles we still have left to drink:
<
Button:[hyphen],Button:1,Button:[equals],Button:[hyphen],Button:1,Button:[equals],
Button:[hyphen],Button:1,Button:[equals],Button:[hyphen],Button:1,Button:[equals],
Button:[hyphen],Button:1,Button:[equals],Button:[hyphen],Button:1,Button:[equals],
Button:[hyphen],Button:1,Button:[equals],Button:[hyphen],Button:1,Button:[equals]
</syntaxhighlight>
We haven't drank all of the bottles at this point, but we can keep going, if we want.
=={{header|Halon}}==
<
$x = 99;
while ($x > 0) {
Line 3,656 ⟶ 5,410:
else
echo "No more bottles of beer on the wall!";
}</
=={{header|Haskell}}==
Line 3,662 ⟶ 5,416:
A relatively concise solution:
<
beer 1 = "1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around"
beer 0 = "better go to the store and buy some more."
Line 3,668 ⟶ 5,422:
++ show v
++" bottles of beer\nTake one down, pass it around\n"
++ head (lines $ beer $ v-1) ++ "\n"</
====List comprehension====
As a list comprehension:
<
main = putStr $ concat
Line 3,687 ⟶ 5,441:
num n = show n
s 1 = ""
s _ = "s"</
====Writer monad and Template Haskell====
Another version, which uses a Writer monad to collect each part of the song. It also uses Template Haskell to generate the song at compile time.
<
-- build with "ghc --make beer.hs"
module Main where
Line 3,719 ⟶ 5,473:
in return $ LitE $ StringL $ song)
main = putStr songString</
====Avoiding append by spelling bottle backwards====
Is there something just a little prickly and displeasing about (++) ?
Monoid (<>) is less spiky, but neither is needed when 'bottle' is written backwards.
<
[location, distribution, solution] =
[ "on the wall",
]
incantation :: Int -> String
incantation n
| 0 == n = solution
| otherwise =
unlines
[ inventory n,
asset n,
distribution,
inventory $ pred n
]
inventory :: Int -> String
inventory = unwords . (: [location]) . asset
asset :: Int -> String
Line 3,736 ⟶ 5,504:
| 1 == n = []
| otherwise = ['s']
in unwords
[show n, (reverse . concat) $ suffix n : ["elttob"]]
main :: IO ()
main = putStrLn $ unlines (incantation <$> [99, 98 .. 0])</
=={{header|Haxe}}==
=== Simple solution ===
<
{
static public function main()
Line 3,782 ⟶ 5,544:
}
}
}</
=== Macro solution ===
Line 3,788 ⟶ 5,550:
Let's generate that print with macro.
<
static public function main () : Void {
Line 3,820 ⟶ 5,582:
}
}</
=={{header|hexiscript}}==
<
let bottle " bottles of "
if amount = 0; let amount "No more"
Line 3,844 ⟶ 5,606:
println take "one" "down" + pass "it" "around"
println bottles (--amount) "beer" "on the wall\n"
endwhile</
=={{header|HicEst}}==
<
WRITE() x , "bottles of beer on the wall"
BEEP("T16 be be be bH bH bH be be be 2be ")
Line 3,859 ⟶ 5,621:
WRITE() x , "bottles of beer on the wall"
BEEP("2p #A #A #A c c d #d #d #d 2#d 2p")
ENDDO</
=={{header|
The default is 99 bottles, but it can be modified by the parameter.
<
// This is made I64 rather than U64
// Because, a U64 would overflow
Line 3,922 ⟶ 5,655:
// Calls the function, which goes to the default parameters
BottlesOfBeer;
</syntaxhighlight>
=={{header|Hoon}}==
<syntaxhighlight lang="hoon">
:- %say
|= [* * [bottles=_99 ~]]
:- %noun
^- wall
=/ output `(list tape)`~
|-
?: =(1 bottles)
%- flop
:- "1 bottle of beer on the wall"
:- "Take one down, pass it around"
:- "1 bottle of beer"
:- "1 bottle of beer on the wall"
output
%= $
bottles (dec bottles)
output
:- "{<bottles>} bottles of beer on the wall"
:- "Take one down, pass it around"
:- "{<bottles>} bottles of beer"
:- "{<bottles>} bottles of beer on the wall"
output
==
</syntaxhighlight>
=={{header|Hope}}==
El código es de Wolfgang Lohmann (wlohmann@informatik.uni-rostock.de)
<syntaxhighlight lang="hope">dec app :( list ( char ) X list ( char )) -> list ( char ) ;
dec i2c : num -> char;
dec i2s : num -> list(char);
dec beer : num -> list(char);
--- app ( nil , w )
<= w ;
--- app (( a :: v ), w )
<=( a :: app ( v , w )) ;
--- i2c(0) <= '0';
--- i2c(1) <= '1';
--- i2c(2) <= '2';
--- i2c(3) <= '3';
--- i2c(4) <= '4';
--- i2c(5) <= '5';
--- i2c(6) <= '6';
--- i2c(7) <= '7';
--- i2c(8) <= '8';
--- i2c(9) <= '9';
--- i2s(x) <= if x < 10 then [i2c(x)] else
app(i2s(x div 10), i2s( x mod 10));
--- beer(x) <= if x = 1 then app( i2s(x),
" bottle of beer. No more beer on the wall.")
else app( app( app( app( app(
i2s(x),
" bottles of beer on the wall, "),
i2s(x)),
" bottles of beer. "),
"Take one down, pass it around. "),
beer(y))
where y== x-1;</syntaxhighlight>
=={{header|HQ9+}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|Huginn}}==
<syntaxhighlight lang="huginn">#! /bin/sh
exec huginn --no-argv -E "${0}" "${@}"
#! huginn
import Algorithms as algo;
main() {
x = "{} bottle{} of beer on the wall,\n"
"{} bottle{} of beer.\n"
"Take one down, pass it around,\n"
"{} bottle{} of beer on the wall.\n\n";
for ( n : algo.range( 99, 0, -1 ) ) {
bot = n > 0 ? n : "No";
plu = n != 1 ? "s" : "";
print( x.format( bot, plu, bot, plu, n > 1 ? n - 1 : "No", n != 2 ? "s" : "" ) );
}
print(
"No bottles of beer on the wall,\n"
"No bottles of beer.\n"
"Go to the store, buy some more,\n"
"99 bottles of beer on the wall.\n"
);
return ( 0 );
}</syntaxhighlight>
=={{header|HyperTalk}}==
El código es de Eric Carlson eric@bungdabba.com
<syntaxhighlight lang="hypertalk">on BeerSong99
BottlesOfBeer 99
end BeerSong99
on OutputBeerLyric beerString
if ( beerString is "<reset>" ) then
put empty into cd fld "beer song"
else
put beerString & return after cd fld "beer song"
end if
end OutputBeerLyric
on BottlesOfBeer bottleCount
put bottleCount into initialCount
OutputBeerLyric "<reset>"
repeat until ( bottleCount < 1 )
set cursor to busy -- let 'em know this might take a while
put BottleString(bottleCount) into currentString
OutputBeerLyric currentString && "of beer on the wall,"
OutputBeerLyric currentString && "of beer."
OutputBeerLyric "Take one down, and pass it around,"
subtract one from bottleCount
OutputBeerLyric BottleString(bottleCount) && "of beer on the wall." & return
end repeat
OutputBeerLyric "Go to the store and buy some more..."
OutputBeerLyric initialCount & " bottles of beer on the wall."
end BottlesOfBeer
function BottleString bottleCount
if ( bottleCount is 1 ) then
return "1 bottle"
else if ( bottleCount is 0 ) then
return "no more bottles"
else
return bottleCount && "bottles"
end if
end BottleString</syntaxhighlight>
=={{header|Icon}} and {{header|Unicon}}==
The default is 99 bottles, but you can change this on the command line for
really long trips...
<
numBeers := integer(args[1]) | 99
drinkUp(numBeers)
Line 3,953 ⟶ 5,822:
write("Go to the store and buy some more, ",
beerMax," bottles of beer on the wall.")
end</
=={{header|IDL}}==
<
for i=1,99 do begin
Line 3,965 ⟶ 5,834:
End
</syntaxhighlight>
Since in IDL "FOR"-loops are the embodiment of pure evil (see http://www.idlcoyote.com/tips/forloops.html and http://www.idlcoyote.com/tips/forloops2.html) there is also a loop free IDL way:
<
b=(reverse(shift(sindgen(100),-1)))[1:99]
b2=reverse(sindgen(99))
Line 3,976 ⟶ 5,845:
takeT=replicate('Take one down, pass it around,', 100)
print, b+wallT+string(10B)+b+wallT2+string(10B)+takeT+string(10B)+b2+wallT+string(10B)
End</
I found the above example very helpful but overdone. This is a more simple version:
<
n_bottles=99
b1 = reverse(SINDGEN(n_bottles,START=1))
Line 3,988 ⟶ 5,857:
takeT=replicate('Take one down, pass it around,', n_bottles)
print, b1+wallT+string(10B)+b1+wallT2+string(10B)+takeT+string(10B)+b2+wallT+string(10B)
End</
=={{header|Idris}}==
<syntaxhighlight lang="idris">
beerSong : Fin 100 -> String
beerSong x = verses x where
Line 4,011 ⟶ 5,880:
verses fZ = ""
verses (fS n) = (verse (fS n)) ++ (verses n)
</syntaxhighlight>
=={{header|Inform 6}}==
<
if(i == 1) return "bottle";
Line 4,033 ⟶ 5,902:
Beer(99);
];
</syntaxhighlight>
=={{header|Inform 7}}==
=== Programmatic solution ===
<
When play begins:
Line 4,046 ⟶ 5,915:
say "Take one down, pass it around[line break]";
say "[N - 1] bottle[s] of beer on the wall[paragraph break]";
end the story.</
=== World model solution ===
This solution uses in-game objects to represent the wall and the bottles.
<
The plural of bottle of beer is bottles of beer. A bottle of beer is a kind of thing.
Line 4,068 ⟶ 5,937:
To say what's on the wall:
if more than one thing is on the wall, say list of things on the wall;
otherwise say "[number of things on the wall in words] bottle[s] of beer".</
=={{header|Io}}==
<
if(i==0, return "no more bottles of beer")
if(i==1, return "1 bottle of beer")
Line 4,086 ⟶ 5,952:
bottles(i - 1), " on the wall.\n\n"
)
)</
=={{header|Intercal}}==
<syntaxhighlight lang="intercal">PLEASE DO ,10 <- #1
PLEASE DO ,10SUB#1 <- #176
PLEASE DO ,11 <- #30
PLEASE DO ,11SUB#1 <- #76
DO ,11SUB#2 <- #190
DO ,11SUB#3 <- #80
DO ,11SUB#4 <- #200
PLEASE DO ,11SUB#5 <- #256
DO ,11SUB#6 <- #248
DO ,11SUB#7 <- #144
DO ,11SUB#8 <- #216
PLEASE DO ,11SUB#9 <- #202
DO ,11SUB#10 <- #14
DO ,11SUB#11 <- #144
DO ,11SUB#12 <- #98
PLEASE DO ,11SUB#13 <- #190
DO ,11SUB#14 <- #160
DO ,11SUB#15 <- #256
DO ,11SUB#16 <- #88
PLEASE DO ,11SUB#17 <- #74
DO ,11SUB#18 <- #14
DO ,11SUB#19 <- #128
DO ,11SUB#20 <- #114
PLEASE DO ,11SUB#21 <- #214
DO ,11SUB#22 <- #24
DO ,11SUB#23 <- #112
DO ,11SUB#24 <- #162
PLEASE DO ,11SUB#25 <- #22
DO ,11SUB#26 <- #104
DO ,11SUB#27 <- #80
DO ,11SUB#28 <- #256
PLEASE DO ,11SUB#29 <- #2
DO ,11SUB#30 <- #228
PLEASE DO ,12 <- #49
PLEASE DO ,12SUB#1 <- #76
DO ,12SUB#2 <- #190
DO ,12SUB#3 <- #80
DO ,12SUB#4 <- #200
PLEASE DO ,12SUB#5 <- #256
DO ,12SUB#6 <- #248
DO ,12SUB#7 <- #144
DO ,12SUB#8 <- #216
PLEASE DO ,12SUB#9 <- #202
DO ,12SUB#10 <- #14
DO ,12SUB#11 <- #144
DO ,12SUB#12 <- #98
PLEASE DO ,12SUB#13 <- #190
DO ,12SUB#14 <- #160
DO ,12SUB#15 <- #256
DO ,12SUB#16 <- #88
PLEASE DO ,12SUB#17 <- #218
DO ,12SUB#18 <- #36
DO ,12SUB#19 <- #38
DO ,12SUB#20 <- #164
PLEASE DO ,12SUB#21 <- #176
DO ,12SUB#22 <- #48
DO ,12SUB#23 <- #162
DO ,12SUB#24 <- #14
PLEASE DO ,12SUB#25 <- #128
DO ,12SUB#26 <- #208
DO ,12SUB#27 <- #162
DO ,12SUB#28 <- #222
PLEASE DO ,12SUB#29 <- #48
DO ,12SUB#30 <- #8
DO ,12SUB#31 <- #120
DO ,12SUB#32 <- #66
PLEASE DO ,12SUB#33 <- #48
DO ,12SUB#34 <- #246
DO ,12SUB#35 <- #136
DO ,12SUB#36 <- #184
PLEASE DO ,12SUB#37 <- #256
DO ,12SUB#38 <- #202
DO ,12SUB#39 <- #110
DO ,12SUB#40 <- #104
PLEASE DO ,12SUB#41 <- #42
DO ,12SUB#42 <- #126
DO ,12SUB#43 <- #56
DO ,12SUB#44 <- #88
PLEASE DO ,12SUB#45 <- #72
DO ,12SUB#46 <- #56
DO ,12SUB#47 <- #80
DO ,12SUB#48 <- #242
PLEASE DO ,12SUB#49 <- #228
PLEASE DO ,13 <- #31
PLEASE DO ,13SUB#1 <- #76
DO ,13SUB#2 <- #190
DO ,13SUB#3 <- #80
DO ,13SUB#4 <- #200
PLEASE DO ,13SUB#5 <- #256
DO ,13SUB#6 <- #248
DO ,13SUB#7 <- #144
DO ,13SUB#8 <- #216
PLEASE DO ,13SUB#9 <- #202
DO ,13SUB#10 <- #14
DO ,13SUB#11 <- #144
DO ,13SUB#12 <- #98
PLEASE DO ,13SUB#13 <- #190
DO ,13SUB#14 <- #160
DO ,13SUB#15 <- #256
DO ,13SUB#16 <- #88
PLEASE DO ,13SUB#17 <- #74
DO ,13SUB#18 <- #14
DO ,13SUB#19 <- #128
DO ,13SUB#20 <- #114
PLEASE DO ,13SUB#21 <- #214
DO ,13SUB#22 <- #24
DO ,13SUB#23 <- #112
DO ,13SUB#24 <- #162
PLEASE DO ,13SUB#25 <- #22
DO ,13SUB#26 <- #104
DO ,13SUB#27 <- #80
DO ,13SUB#28 <- #256
PLEASE DO ,13SUB#29 <- #194
DO ,13SUB#30 <- #36
DO ,13SUB#31 <- #256
PLEASE DO ,20 <- #10
PLEASE DO ,20 SUB #1 <- #76
DO ,20 SUB #2 <- #196
DO ,20 SUB #3 <- #4
DO ,20 SUB #4 <- #132
PLEASE DO ,20 SUB #5 <- #36
DO ,20 SUB #6 <- #164
DO ,20 SUB #7 <- #228
DO ,20 SUB #8 <- #100
PLEASE DO ,20 SUB #9 <- #52
DO ,20 SUB #10 <- #180
PLEASE DO ,21 <- #10 BY #10
PLEASE DO ,21SUB#1#1 <- #248
PLEASE DO ,21SUB#1#2 <- #120
PLEASE DO ,21SUB#1#3 <- #184
PLEASE DO ,21SUB#1#4 <- #56
PLEASE DO ,21SUB#1#5 <- #216
PLEASE DO ,21SUB#1#6 <- #88
PLEASE DO ,21SUB#1#7 <- #152
PLEASE DO ,21SUB#1#8 <- #24
PLEASE DO ,21SUB#1#9 <- #232
PLEASE DO ,21SUB#1#10 <- #104
DO ,21SUB#2#1 <- #128
DO ,21SUB#2#2 <- #256
DO ,21SUB#2#3 <- #64
DO ,21SUB#2#4 <- #192
DO ,21SUB#2#5 <- #96
DO ,21SUB#2#6 <- #224
DO ,21SUB#2#7 <- #32
DO ,21SUB#2#8 <- #160
DO ,21SUB#2#9 <- #112
DO ,21SUB#2#10 <- #240
DO ,21SUB#3#1 <- #64
DO ,21SUB#3#2 <- #192
DO ,21SUB#3#3 <- #256
DO ,21SUB#3#4 <- #128
DO ,21SUB#3#5 <- #32
DO ,21SUB#3#6 <- #160
DO ,21SUB#3#7 <- #224
DO ,21SUB#3#8 <- #96
DO ,21SUB#3#9 <- #48
DO ,21SUB#3#10 <- #176
DO ,21SUB#4#1 <- #192
DO ,21SUB#4#2 <- #64
DO ,21SUB#4#3 <- #128
DO ,21SUB#4#4 <- #256
DO ,21SUB#4#5 <- #160
DO ,21SUB#4#6 <- #32
DO ,21SUB#4#7 <- #96
DO ,21SUB#4#8 <- #224
DO ,21SUB#4#9 <- #176
DO ,21SUB#4#10 <- #48
PLEASE DO ,21SUB#5#1 <- #32
PLEASE DO ,21SUB#5#2 <- #160
PLEASE DO ,21SUB#5#3 <- #224
PLEASE DO ,21SUB#5#4 <- #96
PLEASE DO ,21SUB#5#5 <- #256
PLEASE DO ,21SUB#5#6 <- #128
PLEASE DO ,21SUB#5#7 <- #192
PLEASE DO ,21SUB#5#8 <- #64
PLEASE DO ,21SUB#5#9 <- #16
PLEASE DO ,21SUB#5#10 <- #144
DO ,21SUB#6#1 <- #160
DO ,21SUB#6#2 <- #32
DO ,21SUB#6#3 <- #96
DO ,21SUB#6#4 <- #224
DO ,21SUB#6#5 <- #128
DO ,21SUB#6#6 <- #256
DO ,21SUB#6#7 <- #64
DO ,21SUB#6#8 <- #192
DO ,21SUB#6#9 <- #144
DO ,21SUB#6#10 <- #16
DO ,21SUB#7#1 <- #96
DO ,21SUB#7#2 <- #224
DO ,21SUB#7#3 <- #32
DO ,21SUB#7#4 <- #160
DO ,21SUB#7#5 <- #64
DO ,21SUB#7#6 <- #192
DO ,21SUB#7#7 <- #256
DO ,21SUB#7#8 <- #128
DO ,21SUB#7#9 <- #80
DO ,21SUB#7#10 <- #208
DO ,21SUB#8#1 <- #224
DO ,21SUB#8#2 <- #96
DO ,21SUB#8#3 <- #160
DO ,21SUB#8#4 <- #32
DO ,21SUB#8#5 <- #192
DO ,21SUB#8#6 <- #64
DO ,21SUB#8#7 <- #128
DO ,21SUB#8#8 <- #256
DO ,21SUB#8#9 <- #208
DO ,21SUB#8#10 <- #80
PLEASE DO ,21SUB#9#1 <- #16
PLEASE DO ,21SUB#9#2 <- #144
PLEASE DO ,21SUB#9#3 <- #208
PLEASE DO ,21SUB#9#4 <- #80
PLEASE DO ,21SUB#9#5 <- #240
PLEASE DO ,21SUB#9#6 <- #112
PLEASE DO ,21SUB#9#7 <- #176
PLEASE DO ,21SUB#9#8 <- #48
PLEASE DO ,21SUB#9#9 <- #256
PLEASE DO ,21SUB#9#10 <- #128
DO ,21SUB#10#1 <- #144
DO ,21SUB#10#2 <- #16
DO ,21SUB#10#3 <- #80
DO ,21SUB#10#4 <- #208
DO ,21SUB#10#5 <- #112
DO ,21SUB#10#6 <- #240
DO ,21SUB#10#7 <- #48
DO ,21SUB#10#8 <- #176
DO ,21SUB#10#9 <- #128
DO ,21SUB#10#10 <- #256
PLEASE DO ,22 <- #10
PLEASE DO ,22 SUB #1 <- #8
DO ,22 SUB #2 <- #136
DO ,22 SUB #3 <- #72
DO ,22 SUB #4 <- #200
PLEASE DO ,22 SUB #5 <- #40
DO ,22 SUB #6 <- #168
DO ,22 SUB #7 <- #104
DO ,22 SUB #8 <- #232
PLEASE DO ,22 SUB #9 <- #24
DO ,22 SUB #10 <- #152
DO .10 <- #9
DO .11 <- #9
PLEASE DO ,10 <- #1
PLEASE DO ,10SUB#1 <- #176
DO READ OUT ,10
DO COME FROM (999)
DO (500) NEXT
PLEASE DO ,11SUB#1 <- .5
DO READ OUT ,11
DO (500) NEXT
DO ,12SUB#1 <- .5
PLEASE DO READ OUT ,12
PLEASE DO .6 <- '?"!10~.10'~#1"$#1'~#3
DO (50) NEXT
PLEASE DO .7 <- '?"!11~.11'~#1"$#1'~#3
DO (70) NEXT
DO .2 <- #1
DO .1 <- .11
PLEASE DO (1010) NEXT
DO .11 <- .3
DO (600) NEXT
DO (101) NEXT
(70) DO (71) NEXT
DO .11 <- #9
DO .2 <- #1
PLEASE DO .1 <- .10
DO (1010) NEXT
DO .10 <- .3
DO (600) NEXT
DO (101) NEXT
(71) DO RESUME .7
(50) DO (51) NEXT
PLEASE DO FORGET #1
DO .2 <- #1
DO .1 <- .11
PLEASE DO (1010) NEXT
DO .11 <- .3
DO (600) NEXT
PLEASE DO .7 <- '?"!11~.11'~#1"$#1'~#3
DO (80) NEXT
DO (101) NEXT
(80) DO (81) NEXT
DO GIVE UP
(81) DO RESUME .7
(51) DO RESUME .6
(101) DO FORGET #1
(999) DO FORGET #1
(600) DO (500) NEXT
DO ,13SUB#1 <- .5
DO READ OUT ,13
DO RESUME #1
(500) DO ,30 <- #1
DO .1 <- .10
DO (1020) NEXT
PLEASE DO ,30SUB#1 <- ,20SUB.1
DO READ OUT ,30
DO .3 <- .1
DO .1 <- .11
DO (1020) NEXT
PLEASE DO ,30SUB#1 <- ,21SUB .3 .1
DO READ OUT ,30
DO .5 <- ,22SUB.1
PLEASE DO RESUME #1</syntaxhighlight>
=={{header|Ioke}}==
<
case(i,
0, "no more bottles of beer",
Line 4,099 ⟶ 6,268:
"take one down, pass it around," println
"#{bottle(i - 1)} on the wall.\n" println
)</
=={{header|J}}==
As posted at the [http://www.jsoftware.com/jwiki/Essays/99_Bottles_of_Beer J wiki]
<
bobw=: bob , ' on the wall'"_
beer=: bobw , ', ' , bob , '; take one down and pass it around, ' , bobw@<:
beer"0 >:i.-99</
{{Out}}
Line 4,115 ⟶ 6,284:
2 bottles of beer on the wall, 2 bottles of beer; take one down and pass it around, 1 bottle of beer on the wall
1 bottle of beer on the wall, 1 bottle of beer; take one down and pass it around, 0 bottles of beer on the wall </pre>
=={{header|Jakt}}==
<syntaxhighlight lang="jakt">
fn bottle_string(bottle_count: i64) throws -> String => match bottle_count {
0 => "No more bottles"
1 => "1 bottle"
else => format("{} bottles", bottle_count)
}
fn main() {
mut bottle_count = 99
while bottle_count > 0 {
println("{} of beer on the wall", bottle_string(bottle_count))
println("{} of beer", bottle_string(bottle_count))
println("Take one down, pass it around")
bottle_count--
println("{} of beer on the wall", bottle_string(bottle_count))
if bottle_count > 0 {
println("")
}
}
}
</syntaxhighlight>
=={{header|Janet}}==
<syntaxhighlight lang="janet">
(defn bottles [n]
(match n
0 "No more bottles"
1 "1 bottle"
_ (string n " bottles")))
(loop [i :down [99 0]]
(print
(bottles i) " of beer on the wall\n"
(bottles i) " of beer\nTake one down, pass it around\n"
(bottles (- i 1)) " of beer on the wall\n\n"))
</syntaxhighlight>
=={{header|Java}}==
===Console===
MessageFormat's choice operator is used to properly format plurals.
<
public class Beer {
Line 4,137 ⟶ 6,345:
}
}
}</
'''Optimized for speed and few I/O operations'''
<
public static void main(String[] args) {
int bottles = 99;
Line 4,153 ⟶ 6,361:
System.out.println(sb.append(verse3));
}
}</
'''Recursive'''
<
public static void main(String args[]) {
song(99);
Line 4,172 ⟶ 6,380:
}
}
}</
=== An object-oriented solution ===
Line 4,183 ⟶ 6,391:
{{libheader|AWT}}
This version requires user interaction. The first two lines are shown in a text area on a window. The third line is shown on a button which you need to click to see the fourth line in a message box. The numbers update and the process repeats until "0 bottles of beer on the wall" is shown in a message box, when the program ends.
<
import java.awt.event.ActionEvent;
import javax.swing.JButton;
Line 4,223 ⟶ 6,431:
}
}
}</
=={{header|JavaScript}}==
===ES3-5===
<
while (beer > 0) {
var verse = [
Line 4,240 ⟶ 6,448:
beer--;
}
</syntaxhighlight>
===ES6===
<
while (beer > 0) {
let verse = `${beer} bottles of beer on the wall,
Line 4,252 ⟶ 6,460:
console.log(verse);
beer--;
}</
===Functional / Recursive===
<
var songTemplate = "{X} bottles of beer on the wall \n" +
"{X} bottles of beer \n"+
Line 4,265 ⟶ 6,473:
}
console.log(song(bottles, songTemplate));</
===Other Examples===
Line 4,271 ⟶ 6,479:
Comment: This being a "one-liner" is arguable. The author has chosen not to put a line break after the declaration of the <code>beer</code> variable. By using the authors definition, most of the other solutions could pass as a "one-liner".
<
var beer; while ((beer = typeof beer === "undefined" ? 99 : beer) > 0) document.write( beer + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall<br>" + beer + " bottle" + (beer != 1 ? "s" : "") + " of beer<br>Take one down, pass it around<br>" + (--beer) + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall<br>" );</
Legitimate "one-liner" with grammar check, using declarative methods.
<
Object Oriented
<
this.count = count || 99;
}
Line 4,304 ⟶ 6,512:
var bar = new Bottles(99);
bar.sing();</
An alternative version:
<
if (!isFinite(Number(n)) || n == 0) n = 100;
var a = '%% bottles of beer',
Line 4,325 ⟶ 6,533:
}
window.onload = bottleSong;</
=={{header|Joy}}==
<
_beerlib == true
HIDE
beer == "of beer " putchars
wall == "on the wall" putchars
take1 == "Take one down and pass it around, " putchars
dup3 == dup dup dup
comma == ", " putchars
period ==
bottles == [
[
[put "bottles " putchars] ifte
sing-verse == dup3 bottles beer wall comma
bottles beer ".\n" putchars
take1
sing-verse-0 == "No more bottles of beer on the wall, no more bottles of beer\n" putchars
"Go to the store and buy some more, " putchars
99 bottles pop beer wall period newline
IN
Line 4,353 ⟶ 6,561:
sing-verses == [null]
[sing-verse-0]
[sing-verse
END.
99 sing-verses.</syntaxhighlight>
=={{header|jq}}==
'''Minimalist:'''
<
| (. - range(0;.+1) )
| "
Line 4,363 ⟶ 6,574:
\(.) bottles of beer
Take one down, pass it around
\(.) bottles of beer on the wall"</
{{out}}
<
...
Line 4,381 ⟶ 6,592:
0 bottles of beer
Take one down, pass it around
0 bottles of beer on the wall</
'''Variant''':
<
def s: if . == 1 then "" else "s" end;
def bottles:
Line 4,397 ⟶ 6,608:
;
$bottles | tonumber | sing</
{{out}}
<
...
2 bottles of beer on the wall
Line 4,414 ⟶ 6,625:
No more bottles of beer
Take one down, pass it around
No more bottles of beer on the wall.</
=={{header|Jsish}}==
<syntaxhighlight lang="jsish">/* 99 Bottles, in Jsish */
function plural(n:number):string { return (bottles == 1) ? "" : "s"; }
function no(n:number):string { return (bottles == 0) ? "No" : n.toString(); }
var bottles = 99;
do {
printf("%d bottle%s of beer on the wall\n", bottles, plural(bottles));
printf("%d bottle%s of beer\n", bottles, plural(bottles));
puts("Take one down, pass it around");
bottles--;
printf("%s bottle%s of beer on the wall\n\n", no(bottles), plural(bottles));
} while (bottles > 0);</syntaxhighlight>
=={{header|Julia}}==
'''one-liner'''
<
another solution, handling grammar cases "No more bottles", "1 bottle", "<n> bottles"
<
n==1 ? "1 bottle" :
"$n bottles"
Line 4,431 ⟶ 6,656:
$(bottles(n-1)) of beer on the wall
""")
end</
shorter, but more cryptic, version of the previous `bottles` function
<
=={{header|K}}==
<
=={{header|Kabap}}==
<syntaxhighlight lang="kabap">
// Loop that spits lyrics to "99 Bottles of Beer"
Line 4,452 ⟶ 6,677:
return = $out;
</syntaxhighlight>
=={{header|Kitten}}==
<
define bottles_of_beer_on_the_wall (Int32 -> +IO):
Line 4,487 ⟶ 6,712:
"one bottle"
else:
n show " bottles" cat</
=={{header|Klingphix}}==
<syntaxhighlight lang="text">include ..\Utilitys.tlhy
:bottles
dup 0 ==
(
["no more bottles of beer"]
[ dup 1 ==
(
["1 bottle of beer"]
[dup tostr " bottles of beer" chain]
) if
]
) if
;
( 99 1 -1 )
[ bottles print " on the wall," ?
bottles "," chain ?
"take one down, pass it around," ?
1 - bottles print " on the wall." ? nl
drop] for
" " input</syntaxhighlight>
=={{header|Klong}}==
<
itone::{:[x=1;"it";"one"]}
numno::{:[x=0;"no";x]}
Line 4,508 ⟶ 6,758:
.d(bottles(x-1));
.p(" of beer on the wall");.p("")}
drink'1+|!99</
=={{header|Kotlin}}==
<
for (i in 99.downTo(1)) {
println("$i bottles of beer on the wall")
Line 4,518 ⟶ 6,768:
}
println("No more bottles of beer on the wall!")
}</
=={{header|LabVIEW}}==
Line 4,526 ⟶ 6,776:
The signature file:
<
type println string -> o.
type round int -> o.
type bottles_song int -> o.
</syntaxhighlight>
The module file:
<
println Str :- print Str, print "\n".
Line 4,556 ⟶ 6,806:
M is N - 1,
bottles_song M.
</syntaxhighlight>
Then we produce the desired output by setting the system to solve for this goal:
<syntaxhighlight lang="lambda
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def beer
{lambda {:i}
{br}:i bottles of beer on the wall
{br}:i bottles of beer
{br}Take one down, pass it around
{br}{- :i 1} bottles of beer on the wall
{br}
}}
{S.map beer {S.serie 99 98 -1}}
...
{S.map beer {S.serie 2 1 -1}}
->
99 bottles of beer on the wall
99 bottles of beer
Take one down, pass it around
98 bottles of beer on the wall
98 bottles of beer on the wall
98 bottles of beer
Take one down, pass it around
97 bottles of beer on the wall
...
2 bottles of beer on the wall
2 bottles of beer
Take one down, pass it around
1 bottles of beer on the wall
1 bottles of beer on the wall
1 bottles of beer
Take one down, pass it around
0 bottles of beer on the wall
</syntaxhighlight>
=={{header|Lang}}==
<syntaxhighlight lang="lang">
$i = 99
until($i == 0) {
fn.println($i bottles of beer on the wall)
fn.println($i bottles of beer)
fn.println(Take one down, pass it around)
$i -= 1
if($i > 0) {
fn.println($i bottles of beer)
fn.println()
}else {
fn.println(No more bottles of beer on the wall)
}
}
</syntaxhighlight>
=={{header|lang5}}==
<syntaxhighlight lang="lang5">: ~ 2 compress "" join ;
: verses(*)
dup " bottles of beer on the wall\n" ~ .
dup " bottles of beer\n" ~ .
"Take one down, pass it around\n" .
1 - " bottles of beer on the wall\n\n" ~ .
;
99 iota 1 + reverse verses</syntaxhighlight>
=={{header|Lasso}}==
Line 4,566 ⟶ 6,883:
=== Simple loop ===
<
beer = 99,
song = ''
Line 4,580 ⟶ 6,897:
}
#song</
=== Query Expression ===
<
#beer + ' bottles of beer on the wall' +
#beer + ' bottles of beer\n' +
'Take one down, pass it around\n' +
--#beer + ' bottles of beer on the wall\n'
)->join('\n')</
=== Query Expression with Autocollect ===
<
local(s = 's')
Line 4,604 ⟶ 6,921:
'Take one down, pass it around,<br>'
#n + ' bottle' + #s + ' of beer on the wall.<br><br>'
^}</
=={{header|LaTeX}}==
===Recursive===
<
\newcounter{beer}
\newcommand{\verses}[1]{
\setcounter{beer}{#1}
\par\noindent
\arabic{beer} bottles of beer on the wall,\\
\arabic{beer} bottles of beer!\\
Take one down, pass it around---\\
\addtocounter{beer}{-1}
\arabic{beer} bottles of beer on the wall!\\
\ifnum#1>0
\verses{\value{beer}}
\fi
}
\begin{document}
\verses{99}
\end{document}</
===Iterative===
Line 4,633 ⟶ 6,947:
Just for fun, this version uses Roman numerals.
<
\newcounter{beer}
\newcounter{showC}
\newcommand{\verses}[1]{
\setcounter{beer}{#1}
\loop
\par\noindent
\Roman{beer} bottles of beer on the wall,\\
\Roman{beer} bottles of beer!\\
Take one down, pass it around---\\
\addtocounter{beer}{-1}
% Romans didn't know how to write zero ;-)
\ifnum\value{beer}=0 ZERO \else\Roman{beer} \fi
bottles of beer on the wall!\\
\ifnum\value{beer}>0
\repeat
}
\begin{document}
\verses{99}
\end{document}</
===References===
*Knuth, Donald E. (1984). ''The TeXbook'', Addison Wesley.
=={{header|LDPL}}==
<
DATA:
bottles-in-the-wall is number
Line 4,702 ⟶ 7,001:
end if
repeat
</syntaxhighlight>
=={{header|Lhogho}}==
<
if :i = 0 [output "|No more bottles of beer|]
if :i = 1 [output "|One bottle of beer|]
Line 4,737 ⟶ 7,036:
;Using it:
sing 99</
=={{header|Limbo}}==
<syntaxhighlight lang="limbo">
implement Beer;
Line 4,767 ⟶ 7,066:
}
</syntaxhighlight>
=={{header|Lingo}}==
<
put i & " bottles of beer on the wall"
put i & " bottles of beer"
Line 4,787 ⟶ 7,086:
put "No more bottles of beer"
put "Go to the store and buy some more"
put "99 bottles of beer on the wall"</
=={{header|Lisp}}==
Line 4,808 ⟶ 7,095:
=={{header|Logo}}==
<
if :n = 0 [output [No more bottles]]
if :n = 1 [output [1 bottle]]
Line 4,819 ⟶ 7,106:
print sentence bottles :n-1 [of beer on the wall]
end
for [n 99 1] [verse :n (print)]</
=={{header|Logtalk}}==
<
:- initialization(sing(99)).
Line 4,844 ⟶ 7,131:
write(N), write(' bottles').
:- end_object.</
=={{header|LOLCODE}}==
Line 4,850 ⟶ 7,137:
=={{header|Lua}}==
<
local function plural (bottles) if bottles == 1 then return '' end return 's' end
Line 4,860 ⟶ 7,147:
print (bottles..' bottle'..plural(bottles)..' of beer on the wall')
print ()
end</
With a numeric for-loop and string formatting:
<
%i bottle%s of beer
Take one down, pass it around
Line 4,873 ⟶ 7,160:
for i = 99, 1, -1 do
print(verse:format(i, suffix(i), i, suffix(i), i-1, suffix(i-1)))
end</
Using Lua relational operators and multiple return values:
<
local s = i == 1 and "1 bottle of beer" or
i == 0 and "no more bottles of beer" or
Line 4,887 ⟶ 7,174:
print( string.format("%s on the wall,\n%s,\ntake one down, pass it around,", bottles(i)),
string.format("\n%s on the wall.\n", bottles(i-1)) )
end</
=={{header|Lucid}}==
<
// The print out is a list of lines. So the output is not separated by new lines, rather
// by '[' and ']' -- I cant figure out how to do string concatenation with numbers in lucid.
Line 4,902 ⟶ 7,189:
beer(A) = if A > 0 then A else `No more' fi;
bottle(A) = if A eq 1 then `bottle of beer' else `bottles of beer' fi;
end</
=={{header|NATURAL}}==
El código es de Chris Bednara
<syntaxhighlight lang="natural">DEFINE DATA
LOCAL
01 #BOTTLES (I2)
END-DEFINE
*
FOR #BOTTLES 99 TO 2 STEP -1
IF #BOTTLES < 98
WRITE #BOTTLES ' BOTTLES OF BEER ON THE WALL'
WRITE ' '
END-IF
*
WRITE #BOTTLES ' BOTTLES OF BEER ON THE WALL'
WRITE #BOTTLES ' BOTTLES OF BEER'
WRITE 'TAKE ONE DOWN, PASS IT AROUND'
END-FOR
*
WRITE '1 BOTTLE OF BEER ON THE WALL'
WRITE ' '
WRITE '1 BOTTLE OF BEER ON THE WALL'
WRITE '1 BOTTLE OF BEER'
WRITE 'TAKE IT DOWN, PASS IT AROUND'
WRITE 'NO MORE BOTTLES OF BEER ON THE WALL'
WRITE ' '
WRITE 'NO MORE BOTTLES OF BEER ON THE WALL'
WRITE 'NO MORE BOTTLES OF BEER'
WRITE 'GO TO THE STORE AND BUY SOME MORE'
WRITE '99 BOTTLES OF BEER'
END
WRITE 'TAKE ONE DOWN, PASS IT AROUND'
*
END</syntaxhighlight>
=={{header|M4}}==
<syntaxhighlight lang="m4">define(`BOTTLES', `bottles of beer')dnl
define(`BOTTLE', `bottle of beer')dnl
define(`WALL', `on the wall')dnl
Line 4,914 ⟶ 7,236:
ifelse(`$1',`0',,`TAKE')
ifelse(`$1',`0',,`NINETEEN(eval($1-1))')')dnl
NINETEEN(99)</
=={{header|MACRO-11}}==
<syntaxhighlight lang="macro-11">
;
; 99 BOTTLES OF BEER
; WRITTEN BY: BILL GUNSHANNON
;
.MCALL .PRINT .EXIT
.RADIX 10
MESG1:
CNUM1: .ASCII " "
.ASCII " BOTTLES OF BEER ON THE WALL, "
CNUM2: .ASCII " "
.ASCII " BOTTLES OF BEER."<13><10>
.ASCII "TAKE ONE DOWN AND PASS IT AROUND, "
CNUM3: .ASCII " "
.ASCIZ " BOTTLES OF BEER ON THE WALL."<13><10><10>
MESG2: .ASCII " 2 BOTTLES OF BEER ON THE WALL, "
.ASCII " 2 BOTTLES OF BEER."<13><10>
.ASCII "TAKE ONE DOWN AND PASS IT AROUND, "
.ASCIZ " 1 BOTTLE OF BEER ON THE WALL."<13><10><10>
MESG3: .ASCII " 1 BOTTLE OF BEER ON THE WALL, "
.ASCII " 1 BOTTLE OF BEER."<13><10>
.ASCII "TAKE ONE DOWN AND PASS IT AROUND, "
.ASCIZ "NO MORE BOTTLES OF BEER ON THE WALL."<13><10><10>
MESG4: .ASCII "NO MORE BOTTLES OF BEER ON THE WALL, "
.ASCII "NO MORE BOTTLES OF BEER."<13><10>
.ASCII "GO TO THE STORE AND BUY SOME MORE, "
.ASCIZ "99 BOTTLES OF BEER ON THE WALL."<13><10><10>
.EVEN
COUNT1: .WORD 99 ; STARTING NUMBER OF BOTTLES
PV: .WORD 10.,1, ; POSITION VALUES FOR 2 DIGITS
START:
MOV COUNT1, R0
MOV R0, R5
DEC R5
AGAIN:
MOV #CNUM1, R1
; CONVERT NUMBER OF BOTTLES TO ASCII FOR THE FIRST FIELD
MOV R0,-(SP)
MOV R1,-(SP)
MOV R2,-(SP)
MOV R3,-(SP)
MOV R4,-(SP)
MOV R5,-(SP)
MOV #PV, R3
MOV #2, R2
A1$: MOV #-1,R4
A2$: INC R4
SUB (R3), R0
BCC A2$
ADD (R3)+, R0
ADD #48, R4
MOVB R4, (R1)+
A21$: SOB R2, A1$
; REMOVE LEADING ZERO - JUST LOOKS BETTER THAT WAY
MOV #CNUM1, R1
CMPB (R1), #48
BNE CONT1
MOVB #32, (R1)
CONT1: MOV #CNUM2, R0
; MOVE THE ASCII NUMBER TO FIELD TWO RATHER THAN COMPUTING IT AGAIN
MOVB (R1)+, (R0)+
MOVB (R1), (R0)
MOV R5, R0
MOV #CNUM3, R1
; CONVERT NUMBER OF BOTTLES TO ASCII FOR THE THIRD FIELD
MOV #PV, R3
MOV #2, R2
B1$: MOV #-1,R4
B2$: INC R4
SUB (R3), R0
BCC B2$
ADD (R3)+, R0
ADD #48, R4
MOVB R4, (R1)+
B21$: SOB R2, B1$
; REMOVE LEADING ZERO - JUST LOOKS BETTER THAT WAY
MOV #CNUM3, R1
CMPB (R1), #48
BNE CONT2
MOVB #32, (R1)
CONT2:
MOV (SP)+,R5
MOV (SP)+,R4
MOV (SP)+,R3
MOV (SP)+,R2
MOV (SP)+,R1
MOV (SP)+,R0
; HANDLE SPECIAL GRAMMER CASES
CMP R0, #2
BNE ONE
.PRINT #MESG2
BR DONE
ONE: CMP R0, #1
BNE GREATER
.PRINT #MESG3
BR DONE
GREATER:
.PRINT #MESG1
DONE:
; DECREMENT THE COUNT AND START AGAIN
MOV R5, R0
DEC R5
TST R0
BNE AGAIN
; OUT OF BEER, SEND THEM TO THE STORE
.PRINT #MESG4
; CLEAN UP AND GO BACK TO KMON
.EXIT
.END START</syntaxhighlight>
=={{header|MAD}}==
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
BOTLES = 99
VERSE WALL.(BOTLES)
BOTL.(BOTLES)
PRINT FORMAT TKDWN
BOTLES = BOTLES - 1
WALL.(BOTLES)
PRINT FORMAT EMPTY
WHENEVER BOTLES .G. 0, TRANSFER TO VERSE
INTERNAL FUNCTION(B)
ENTRY TO BOTL.
WHENEVER B .E. 1
PRINT FORMAT ONEBTL
OTHERWISE
PRINT FORMAT BBTL,B
END OF CONDITIONAL
FUNCTION RETURN
END OF FUNCTION
INTERNAL FUNCTION(B)
ENTRY TO WALL.
WHENEVER B .E. 0
PRINT FORMAT NOMORE
OR WHENEVER B .E. 1
PRINT FORMAT ONEOTW
OTHERWISE
PRINT FORMAT BBOTW,B
END OF CONDITIONAL
FUNCTION RETURN
END OF FUNCTION
VECTOR VALUES BBOTW = $I2,S1,27HBOTTLES OF BEER ON THE WALL*$
VECTOR VALUES BBTL = $I2,S1,15HBOTTLES OF BEER*$
VECTOR VALUES TKDWN = $32HTAKE ONE DOWN AND PASS IT AROUND*$
VECTOR VALUES ONEOTW = $S1,29H 1 BOTTLE OF BEER ON THE WALL*$
VECTOR VALUES ONEBTL = $S1,17H 1 BOTTLE OF BEER*$
VECTOR VALUES NOMORE = $35HNO MORE BOTTLES OF BEER ON THE WALL*$
VECTOR VALUES EMPTY = $*$
END OF PROGRAM</syntaxhighlight>
=={{header|make}}==
Line 4,920 ⟶ 7,436:
{{libheader|jot}}
{{works with|BSD make}}
<
UP != jot - 2 `expr $(START) - 1` 1
Line 4,946 ⟶ 7,462:
@echo $(START) bottles of beer on the wall,
@echo $(START) bottles of beer.
@echo Take one down, pass it around.</
Usage: <tt>make</tt> or <tt>make START=99</tt>
Line 4,952 ⟶ 7,468:
=== GNU make ===
{{works with|GNU make|3.81}}
<
1-bottles: 1-beer pass
Line 4,968 ⟶ 7,484:
pass:
@echo "Take one down and pass it around,"</
Usage: <tt>make 99-bottles</tt>
Line 4,977 ⟶ 7,493:
===== Without using a shell command to decrement the counter =====
{{works with|GNU make|3.81}}
<
numbers:=$(foreach x,$(filter-out 0,$(digits)),$(foreach y,$(digits),$x$y))
numbers+=$(digits)
Line 5,030 ⟶ 7,546:
@echo "$(most) $(bottles) $(beer) $(wall)!"
@echo ""
</syntaxhighlight>
Usage: <tt>make</tt> or <tt>make N-bottles</tt> or <tt>make N</tt>
Line 5,039 ⟶ 7,555:
'''Long version''' (a real loop version made by Hisashi Iizawa)''':'''
<
S(bt<%@#!7~|4{y1xv.us+rp(om%lj"ig}fd"cx``uz]rwvYnslkTonPfOjiKgJeG]\EC_X]@[Z<R;VU7S6QP2N1LK-I
,GF(D'BA#?>7~;:9y16w43s10)p-,l*#(i&%e#d!~``{tyxZpuXsrTTongOkdMhg`Hd]ba`_^W@[ZYXW9UNSRQPOHMLK
Line 5,284 ⟶ 7,800:
'qLQn"2~YK-hBG)ccC<NM]K7}|Y{i1U/Ad2sO/LoJIkZFEhf$TA!~>+{]]88Y6XslT0B.zl,=<;(J%d]F!`}BW@yyY+d
tO8Mq5PINkjih-BTecQCa`qp>J~5XzW165eR,bO/L^m8[6j'D%UBdc>}`N^9x&vonF2qCSRmf>M*;J&8^]\n~}}@?[xY
+:Pt8S6o]3l~Y..,,*@RQ</
'''Short version''' (a just printing out the lyrics version made by Johannes E. Schindelin)''':'''
<
R5nO2~L/JzHe@ED'`N$?\7<;:W87C54us1N`.-nm*GF43gU#dRx=_N)sK&vo4Vrqji.z,Odvh'&e7Fb"
DlkAVhZS+Q9(7M_$o"110EhzgxFccbBNqLo\}}Y9z7gT4us1*/LKn87G(!&VeT/c?w|_M(xwY5XmVTjo
Line 5,384 ⟶ 7,900:
RQPO1GFEDh+A@dDCBA@98\65Y9y1Uv.-,+*N.-,%Ij(!~}C#zyxw=^zsrqp6nm3qpoQmlkd*Ka`&G]\[
Z~^]\UyYX:VOs6qQJIm0k.DhHG)?cCBA#98\<|432V65.-Q+*No-&%I)('g}Cdzyxw=^zyxq7on4rTji
h.ledcba'_^$o</
=={{header|Maple}}==
<
i, `if`( i<>1, "bottles", "bottle" ),
i, `if`( i<>1, "bottles", "bottle" ),
i-1, `if`( i-1<>1, "bottles", "bottle") ),
i = 99..1, -1 );</
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
BottleSong[n_] := Speak[
Line 5,403 ⟶ 7,919:
]
BottleSong /@ Range[99,1,-1]</
=={{header|MATLAB}}==
<
disp( [ sprintf(['%d bottles of beer on the wall, %d bottles of beer.\n'...
Line 5,416 ⟶ 7,932:
%beer...like college.
end</
=={{header|Maxima}}==
<
printf(true, "~d bottle~p of beer on the wall~%", i, i),
printf(true, "~d bottle~p of beer~%", i, i),
Line 5,444 ⟶ 7,960:
0 bottles of beer on the wall
*/</
=={{header|MAXScript}}==
<
resetMaxFile #noPrompt
viewport.setType #view_top
Line 5,472 ⟶ 7,988:
redrawViews()
sleep delay
)</
=== A one-line version ===
Since MAXscript is an expression based language (everything returns a value), it is relatively easy to write long expressions that are only one line long. the following single-line snippet (broken for clarity on the webpage) produces a grammatically correct printout of the song.
<
(if i == 1 then " bottle" else " bottles") + " of beer\nTake one down, pass it around\n" + (i - 1) as string + (if i - 1 == 1 then "\
bottle" else " bottles") + " of beer on the wall\n" + (if i - 1 == 0 then "\nno more beer" else "")))</
=={{header|MEL}}==
<syntaxhighlight lang="mel">// Rosetta Code problem: https://rosettacode.org/wiki/99_bottles_of_beer
// by Jjuanhdez, 10/2022
string $temp0[] , $temp1[] , $text0 , $text1;
string $theGrp = `group -em`;
for ($i = 99 ; $i > -1 ; $i--)
{
$text0 = string($i) + " bottles of beer on the wall, " + string($i) +" bottles of beer.";
$text1 = "Take one down and pass it around, " + string($i-1) +" bottles of beer on the wall.";
if ($i == 1)
{
$text0 = string($i) + " bottle of beer on the wall, " + string($i) +" bottle of beer.";
$text1 = "Take one down and pass it around, no more bottles of beer on the wall.";
}
if ($i == 0)
{
$text0 = "No more bottles of beer on the wall, no more bottles of beer. ";
$text1 = "Go to the store and buy some more, 99 bottles of beer on the wall.";
}
$temp0 = `textCurves -ch 0 -f "Times New Roman|h-13|w400|c0" -t ($text0)`;
$temp1 = `textCurves -ch 0 -f "Times New Roman|h-13|w400|c0" -t ($text1)`;
setAttr ($temp0[0] + ".ty") (($i * 8) + 3);
setAttr ($temp1[0] + ".ty") ($i * 8);
parent $temp0[0] $theGrp ;
parent $temp1[0] $theGrp ;
}</syntaxhighlight>
=={{header|Mercury}}==
<syntaxhighlight lang="mercury">
% file: beer.m
% author:
Line 5,543 ⟶ 8,087:
string.format("%d bottles of beer", [i(N)])
).
</syntaxhighlight>
=={{header|min}}==
{{works with|min|0.19.3}}
<
(
Line 5,558 ⟶ 8,102:
) :verse
99 'verse over times</
=={{header|MiniScript}}==
Going for the simple/obvious solution here...
<
if n == 0 then return "no bottles"
if n == 1 then return "1 bottle"
Line 5,578 ⟶ 8,122:
for i in range(99, 1)
verse i
end for</
{{out}}
<pre>99 bottles of beer on the wall
Line 5,603 ⟶ 8,147:
=={{header|MIPS Assembly}}==
<
##################################
# 99 bottles of beer on the wall #
Line 5,681 ⟶ 8,225:
li $v0,10
syscall
</syntaxhighlight>
=={{header|Mirah}}==
<
99.downto(1) do |i|
puts "#{i} bottle#{plural} of beer on the wall,"
Line 5,697 ⟶ 8,241:
end
end
</syntaxhighlight>
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = map (Stdout . verse) [99, 98 .. 1]
verse :: num->[char]
verse n = lay [bottles n ++ " of beer on the wall,",
bottles n ++ " of beer,",
"Take " ++ pronoun ++ " down and pass it around,",
bottles (n-1) ++ " of beer on the wall!",
[]]
where pronoun = "it", if n=1
= "one", otherwise
bottles :: num->[char]
bottles n = "No more bottles", if n=0
= "1 bottle", if n=1
= (show n) ++ " bottles", otherwise</syntaxhighlight>
=={{header|mIRC Scripting Language}}==
<
while (%x) {
echo -ag %x bottles of beer on the wall
Line 5,706 ⟶ 8,269:
dec %x
echo -ag %x bottles of beer on the wall
}</
=={{header|ML/I}}==
=== Simple iterative version ===
<
"" 99 bottles - simple iterative version
MCSKIP MT,<>
Line 5,772 ⟶ 8,292:
>
"" Do it
BOTTLES 99</
=== Recursive version ===
<
"" 99 bottles - recursive version
MCSKIP MT,<>
Line 5,794 ⟶ 8,314:
>
"" Do it
BOTTLES 99</
Line 5,817 ⟶ 8,337:
Internal macros define English word replacements for decimal numbers from 0 to 99.
<syntaxhighlight lang="ml/i">
MCSKIP - WITH - NL
-- The line above defines the comment syntax: -- through to newline is completely deleted.
Line 5,916 ⟶ 8,436:
-- Sing 7 flasks of Armagnac on the table: Take a swig, throw it down!
-- Emilie vists, she brings some more.
</syntaxhighlight>
=== Usage: ===
Line 5,923 ⟶ 8,443:
=== Output: ===
<syntaxhighlight lang="ml/i">
Ninety nine bottles of beer on the wall,
Ninety nine bottles of beer.
Line 5,947 ⟶ 8,467:
Ninety nine bottles of beer on the wall!
</syntaxhighlight>
=={{header|mLite}}==
<syntaxhighlight lang="sml">val NL = implode [#"newline"]
fun itone 1 = "it"
| n = "one"
fun plural (s, 0) = ("no " @ s @ "s")
| (s, 1) = ("1 " @ s)
| (s, n) = (ntos n @ " " @ s @ "s")
fun verse 0 = "no bottles of beer on the wall" @ NL @
"no bottles of beer" @ NL @
"go to the store and buy some more" @ NL @
"99 bottles of beer on the wall" @ NL @ NL
| x = plural ("bottle",x) @ " of beer on the wall" @ NL @
plural ("bottle",x) @ " of beer" @ NL @
"take " @ (itone x) @ " down and pass it round" @ NL @
plural ("bottle", (x-1)) @ " of beer on the wall" @ NL @ NL
fun bottles x = map (print o verse) (rev (0 :: iota (1, x)))
fun default (false, y) = y | (x, _) = x
;
bottles ` ston ` default (argv 0, "99")</syntaxhighlight>
Allows for number of bottles to be specified on command line with the default being 99, viz
<pre>mlite -f 99bob.m 2</pre>
Which, having specified 2 bottles, gives
<pre>2 bottles of beer on the wall
2 bottles of beer
take one down and pass it round
1 bottle of beer on the wall
1 bottle of beer on the wall
1 bottle of beer
take it down and pass it round
no bottles of beer on the wall
no bottles of beer on the wall
no bottles of beer
go to the store and buy some more
99 bottles of beer on the wall</pre>
=={{header|Modula-2}}==
<
IMPORT InOut;
Line 5,972 ⟶ 8,535:
InOut.WriteLn
UNTIL nr = 0
END b99.</
=={{header|Modula-3}}==
<
IMPORT IO, Fmt;
Line 5,987 ⟶ 8,550:
IO.Put("\n");
END;
END Bottles.</
=={{header|Monkey}}==
Tic's every one and a half seconds and sings(text's) the song out.
<
Import mojo
Line 6,068 ⟶ 8,631:
End
</syntaxhighlight>
=={{header|MontiLang}}==
<syntaxhighlight lang="montilang">99 VAR i .
WHILE i
i TOSTR OUT . | bottles of beer on the wall| PRINT .
i TOSTR OUT . | bottles of beer| PRINT .
|Take one down, pass it around| PRINT .
i 1 - VAR i .
ENDWHILE</syntaxhighlight>
Another way to solve the task that shows some more features of the language.
<syntaxhighlight lang="montilang">&DEFINE botellas 99&
def rima
OUT | bottles of beer on the wall| PRINT .
OUT | bottles of beer| PRINT .
enddef
botellas
for :
rima
|Take one down, pass it around| PRINT .
1 -
endfor
|No more| rima
|Press ENTER to end | INPUT clear</syntaxhighlight>
Infinite loop
<syntaxhighlight lang="montilang">99 var botellas .
def rima /# n -- n #/
OUT | bottles of beer on the wall| PRINT .
OUT | bottles of beer| PRINT .
enddef
def song /# n -- #/
for :
rima
|Take one down, pass it around| PRINT .
1 -
endfor
|No more| rima
clear
enddef
while 1
botellas
song
|Go to the store and buy some more, | print
botellas out | bottles of beer on the wall.| print
|Press ENTER to continue | INPUT clear
endwhile</syntaxhighlight>
=={{header|MOO}}==
<
while (bottles > 0)
unit = (bottles == 1 ? "bottle" | "bottles");
Line 6,081 ⟶ 8,700:
bottles = bottles - 1;
endwhile
player:tell("0 bottles of beer on the wall.");</
=={{header|MoonScript}}==
<
i != 1 and 's' or ''
Line 6,096 ⟶ 8,715:
i < 4 and (p b) or (p b-1),
i%3 == 1 and ' on the wall' or ''
io.write '\n'</
=={{header|MUMPS}}==
===Recursive===
<
Write !!,n," bottle",$Select(n=1:"",1:"s")," of beer on the wall."
Write !,n," bottle",$Select(n=1:"",1:"s")," of beer."
Line 6,107 ⟶ 8,726:
Quit
Do beer(99)</
===Iterative===
<
Write !!,n," bottle",$Select(n=1:"",1:"s")," of beer on the wall."
Write !,n," bottle",$Select(n=1:"",1:"s")," of beer."
Line 6,116 ⟶ 8,735:
Quit
For ii=99:-1:0 Do beer(ii)</
===Brain-damaging===
<
set template1="i_n_""of beer on the wall. ""_i_n_"" of beer. """
set template2="""Take""_n2_""down, pass it around. """
Line 6,130 ⟶ 8,749:
repeat
write "One more time!",! hang 5
goto bottles</
=={{header|MyDef}}==
Line 6,147 ⟶ 8,755:
<div>
mydef_page -mgeneral bottles.def
</div>
It outputs bottles.txt, which contains the lyrics.
<
$(for:i in 99-1)
$(i) bottles of beer on the wall
Line 6,158 ⟶ 8,766:
$(i) bottles of beer on the wall
NEWLINE
</syntaxhighlight>
=={{header|N/t/roff}}==
Line 6,166 ⟶ 8,774:
{{works with|All TROFF}}
<
.de L1
.ie \\n(BS>1 \{ \
Line 6,183 ⟶ 8,791:
.nf
.L1
.fi</
===New version (compatible only with GNU TROFF)===
Line 6,189 ⟶ 8,797:
{{works with|GNU TROFF|1.22.2}}
<
.nf
.while \n[beers]>0 \{ \
Line 6,203 ⟶ 8,811:
\n-[beers] bottles of beer on the wall.
\} \" while \n[beers]>0
.fi</
=={{header|Nanoquery}}==
{{trans|Ursa}}
<syntaxhighlight lang="nanoquery">//
// 99 bottles of beer
//
for bottles in range(99, 1, -1)
bottlestr = ""
if bottles = 1
bottlestr = "bottle"
else
bottlestr = "bottles"
end if
println (bottles + " " + bottlestr + " of beer on the wall")
println (bottles + " " + bottlestr + " of beer")
println "Take one down, pass it around."
if !(bottles = 2)
println (bottles - 1 + " bottles of beer on the wall.\n")
else
println "1 bottle of beer on the wall.\n"
end if
end for</syntaxhighlight>
=={{header|NASL}}==
<
repeat {
display(bottles, ' bottles of beer on the wall\n');
Line 6,212 ⟶ 8,846:
display('Take one down, pass it around\n');
display(--bottles, ' bottles of beer on the wall\n\n');
} until bottles < 1;</
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
<doc>
<h3>Rosetta Code, 99 bottles of beer on the wall, in Neko</h3>
Line 6,246 ⟶ 8,879:
$print(nonesome(beers), plural(beers), message);
if (beers > 0) $print("\n");
}</
{{out}}
Line 6,263 ⟶ 8,896:
=={{header|Nemerle}}==
<
using System.Console;
Line 6,286 ⟶ 8,919:
Sing(i)
}
}</
=={{header|NetRexx}}==
<
beer = "bottles of beer on the wall"
removeOne = "Take one down, pass it arround,"
Line 6,309 ⟶ 8,942:
say removeOne
say "No more" beer
</syntaxhighlight>
=={{header|
See [[99 Bottles of Beer/Lisp]]
=={{header|Nial}}==
<
0=, 'No more bottles of beer' first,
1=, 'One bottle of beer' first,
Line 6,327 ⟶ 8,960:
]
bottles is iterate (write verse) reverse count</
=={{header|Night}}==
<syntaxhighlight lang="night">null bottles(int x) {
if(x == 1) {
print("1 bottle of beer on the wall,\n");
print("1 bottle of beer,\n");
print("Take it down, pass it around,\n");
print("No more bottles of beer.\n");
}
else {
print(x);
print(" bottles of beer on the wall,\n");
print(x);
print(" bottles of beer,\n");
print("Take one down, pass it around,\n");
print(x - 1);
print(" bottles of beer on the wall,");
bottles(x-1);
}
}
bottles(1);</syntaxhighlight>
This code ''should'' work according to the docs, but due to a few bugs in the current implementation it doesn't.
=={{header|Nim}}==
<
case n
else:
for bn in countdown(99, 1):
echo(cur, " on the wall, ", cur, ".")
echo("Take one down and pass it around, ",
echo "No more bottles of beer on the wall, no more bottles of beer."
echo "Go to the store and buy some more, 99 bottles of beer on the wall."</
other:
<
for i in countdown(99, 1):
Line 6,370 ⟶ 9,025:
No more bottles of beer on the wall""", i)
else:
discard</
compact:
<
proc pluralize(a: int): string =
if a > 1 or a == 0:
else:
for i in countdown(99, 1):
Line 6,384 ⟶ 9,039:
$1 bottle$3 of beer
Take one down, pass it around
$2 bottle$4 of beer on the wall""", i, i-1, pluralize(i), pluralize(i-1))</
organized:
<
var verse = """$1 bottle$3 of beer on the wall
Line 6,396 ⟶ 9,051:
proc pluralize(a: int): string =
if a > 1 or a == 0:
else:
for i in countdown(99, 1):
echo format(verse, i, i-1, pluralize(i), pluralize(i-1))</
=={{header|Nix}}==
<syntaxhighlight lang="nix">with builtins;
let
bottle = x: "${toString x} bottle${if (x == 1) then "" else "s"} of beer";
beer = { x ? 99 }: if (x == 0) then "" else ''
${bottle x} on the wall
${bottle x}
Take one down, pass it around
${bottle (x - 1)} on the wall
${beer { x = x - 1; }}'';
in
beer { }</syntaxhighlight>
=={{header|NS-HUBASIC}}==
With grammatical support for "1 bottle of beer"
<syntaxhighlight lang="ns-hubasic">10 WALL$=" ON THE WALL"
20 FOR BOTTLES=99 TO 1 STEP -1
30 BOTTLES$=" BOTTLES OF BEER"
40 IF BOTTLES=1 THEN BOTTLE$=" BOTTLE OF BEER"
50 PRINT BOTTLES BOTTLES$ WALL$
60 PRINT BOTTLES BOTTLES$
70 PRINT "TAKE ONE DOWN, PASS IT AROUND"
80 IF BOTTLES-1=1 THEN BOTTLE$=" BOTTLE OF BEER"
90 IF BOTTLES-1=0 THEN BOTTLE$=" BOTTLES OF BEER"
100 PRINT BOTTLES-1 BOTTLES$ WALL$
110 NEXT</syntaxhighlight>
Without grammatical support for "1 bottle of beer"
<syntaxhighlight lang="ns-hubasic">10 BOTTLES$=" BOTTLES OF BEER"
20 WALL$=" ON THE WALL"
30 FOR BOTTLES=99 TO 1 STEP -1
40 PRINT BOTTLES BOTTLES$ WALL$
50 PRINT BOTTLES BOTTLES$
60 PRINT "TAKE ONE DOWN, PASS IT AROUND"
70 PRINT BOTTLES-1 BOTTLES$ WALL$
80 NEXT</syntaxhighlight>
=={{header|Nutt}}==
<syntaxhighlight lang="Nutt">
module main imports native.io.output.say
for i|->{1,2..99;<|>) do
say(""+i+" bottles of beer on the wall, "+i+" bottles of beer")
say("Take one down and pass it around, "+(i-1)+" bottles of beer on the wall.")
done
end
</syntaxhighlight>
=={{header|OASYS}}==
<
class player {}
Line 6,434 ⟶ 9,139:
print "Type 'beer' for beer.\nType 'quit' to quit.\n"
}
</syntaxhighlight>
=={{header|OASYS Assembler}}==
See [[99 Bottles of Beer/Assembly]]
=={{header|Oberon-2}}==
<syntaxhighlight lang="oberon2">MODULE b99;
IMPORT Out;
VAR nr : INTEGER;
BEGIN
nr := 99;
REPEAT
Out.Int (nr, 4);
Out.String (" bottles of beer on the wall");
Out.Ln;
Out.Int (nr, 4);
Out.String (" bottles of beer");
Out.Ln;
Out.String ("Take one down, pass it around");
Out.Ln;
DEC (nr);
Out.Int (nr, 4);
Out.String (" bottles of beer on the wall");
Out.Ln;
Out.Ln
UNTIL nr = 0
END b99.</syntaxhighlight>
=={{header|Objeck}}==
<
class Bottles {
function : Main(args : String[]) ~ Nil {
Line 6,452 ⟶ 9,183:
} while(bottles > 0);
}
}</
=={{header|Objective-C}}==
<
int main()
Line 6,471 ⟶ 9,202:
}
return 0;
}</
=={{header|OCaml}}==
===For-loop===
<
Printf.printf "%d bottles of beer on the wall\n" n;
Printf.printf "%d bottles of beer\n" n;
Printf.printf "Take one down, pass it around\n";
Printf.printf "%d bottles of beer on the wall\n\n" (pred n);
done</
===Recursive===
Recursive version that handles plurals.
<
let
line2 = function
Line 6,535 ⟶ 9,240:
if n > 1 then beer (n-1);;
beer 99;;</
===Monadic===
Monadic version, expressing actions which evolve the program state and log output. Special cases and grammar rules are handled.
<
module Writer = struct
type 'a t = 'a * string
Line 6,565 ⟶ 9,270:
| n -> take n >>= summary |> verse)
let sing start =
Writer.(emit (verse (return start)))</
Output for initial beer-count of two:
<syntaxhighlight lang="text"># sing 2;;
2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.
Line 6,579 ⟶ 9,284:
Go to the store and buy some more, 99 bottles of beer on the wall.
- : int = 99</
Note the output value is 99... reflecting the state at termination.
=={{header|Octave}}==
<
bottle = "bottle";
ofbeer = "of beer";
Line 6,606 ⟶ 9,311:
endfunction
bottles(99);</
=={{header|Odin}}==
<syntaxhighlight lang="odin">package main
import "core:fmt"
printf :: fmt.printf //Give fn on right an arbitrary name, or 9x fmt.printf("...")
bob :: proc( n: int , x: int){
for i := x; i > 0 ; i -=1 {
if n >= 2 do printf("%d bottles of beer",n)
else if n == 1 do printf("1 bottle of beer")
else if n == 0 do printf("No more bottles of beer")
if i == 1 do printf(".\n")
if i > 1 do printf(" on the wall.\n")
if i > 2 do printf("\n")
}
}
main :: proc(){
n := 99
bob(n, 2)
for i := n - 1 ; i >= 0 ; i -= 1 {
printf("Take one down; pass it around.\n")
bob(i, 3)
}
printf ("Go to the store and buy some more.\n")
printf ("%i bottles of beer on the wall.\n",n)
}
</syntaxhighlight>
=={{header|Oforth}}==
<
"bottles of beer\nTake one down, pass it around\n" const: T
#[ 100 swap - dup . B print dup . T print 1- . B .cr ] 99 each </
=={{header|Ol}}==
Line 6,620 ⟶ 9,354:
=={{header|Onyx}}==
<
dup cvs ` bottle' cat exch 1 ne {`s' cat} if
` of beer' cat
Line 6,635 ⟶ 9,369:
} def
99 -1 1 {WriteStanza} for</
Output:
Line 6,653 ⟶ 9,387:
=={{header|OOC}}==
<
sing_line: func (b: Int, suffix: Bool) {
"#{b > 0 ? "#{b}" : "No more"} bottle#{b == 1 ? "" : "s"}" print()
Line 6,678 ⟶ 9,412:
}
}
</syntaxhighlight>
=={{header|ooRexx}}==
Line 6,684 ⟶ 9,418:
=={{header|OpenEdge/Progress}}==
<
&GLOBAL-DEFINE bbm bottles of beer
&GLOBAL-DEFINE bbs bottle of beer
Line 6,716 ⟶ 9,450:
END.
RETURN 0.
END FUNCTION.</
=={{header|Openscad}}==
El código es de Marc Vanlindt (marc@vanlindt.be)
<syntaxhighlight lang="openscad">num_bottles = 99;
s1 = " of beer";
s2 = " on the wall";
s3 = "Take one down and pass it around, ";
s4 = "No more";
s5 = "no more";
s6 = "Go to the store and buy some more, ";
b1 = " bottle";
b2 = " bottles";
beer(n = num_bottles);
module beer(n, biere) {
biere1 = str(n >= 1 ? n : s4,n == 1 ? b1 :b2,s1, s2,", ",n >= 1 ? n : s5,n == 1 ? b1 :b2,s1,".");
biere2 = str(n == 0 ? s6 : s3,n == 0 ? num_bottles : n == 1 ? s5 : n-1,n == 0 ? b2 : n-1 == 1 ? b1 : b2,s1,s2,".");
biere3 = str(biere1," ",biere2);
echo(biere3);
if(n > 0) {
beer(n = n-1);
}
}</syntaxhighlight>
=={{header|Order}}==
Line 6,723 ⟶ 9,479:
==="Pure" Order===
This solution uses only Order language constructs to generate and manipulate tokens:
<
ORDER_PP
Line 6,739 ⟶ 9,495:
(take one down, pass it around,) 8space
8ap(8B, 8dec(8N)) (of beer on the wall.))),
100, 1)))</
===C Preprocessor===
...but since most of the logic is simple substitution, it makes more sense (and is significantly more efficient) to make the C Preprocessor do most of the work without the help of the Order interpreter. This version shows how to integrate normal C Preprocessor macros into an Order program:
<
#define GEN_phrase(N_bottles, N_minus_1_bottles) \
Line 6,766 ⟶ 9,522:
100, 1))
#undef GEN_phrase</
Either example could obviously also form the core of a C solution (demonstrating the intended use of Order).
=={{header|Oxygene}}==
<
namespace ConsoleApplication2;
Line 6,806 ⟶ 9,562:
end.
</syntaxhighlight>
=={{header|Oz}}==
=== Constraint Programming ===
Note: In real life, you would never solve a simple iterative task like this with constraint programming. This is just for fun.
<
%% describe the possible solutions of the beer 'puzzle'
proc {BeerDescription Solution}
Line 6,836 ⟶ 9,591:
%% show all solutions to the 'puzzle'
{ForAll {SearchAll BeerDescription}
System.showInfo}</
=== Iterative ===
<
fun {Bottles N}
if N == 1 then "1 bottle"
Line 6,852 ⟶ 9,607:
"Take one down, pass it around\n"#
{Bottles I-1}#" of beer on the wall\n"}
end</
=={{header|PARI/GP}}==
<
print(n" bottles of beer on the wall");
print(n" bottles of beer");
Line 6,862 ⟶ 9,617:
);
print("2 bottles of beer on the wall\n2 bottles of beer\nTake one down, pass it around\n1 bottle of beer on the wall\n");
print("1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around\nNo more bottles of beer on the wall")</
=={{header|Pascal}}==
See [[99 Bottles of Beer/Pascal]]
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
begin
for var i:=99 to 1 step -1 do
begin
Println(i,'bottles of beer on the wall');
Println(i,'bottles of beer');
Println('Take one down, pass it around');
Println(i-1,'bottles of beer on the wall');
Println
end;
end.</syntaxhighlight>
=={{header|Perl}}==
<
my $verse = <<"VERSE";
Line 6,885 ⟶ 9,653:
print $verse;
redo unless $done;
}</
Alternatively:
<
{
$bottles = sprintf("%s bottle%s of beer on the wall\n",(($n==0)?"No":$n), (($n==1)?"":"s"));
print( (($n==99)?"":"$bottles\n") .
(($n==0)?"":(substr(${bottles}x2,0,-12) . "\nTake one down, pass it around\n")) );
}</
Correct grammar and nice spacing in modern perl:
<
$num = 99;
Line 6,909 ⟶ 9,677:
say "No more bottles of beer on the wall, no more bottles of beer.";
say "Go to the store and buy some more, 99 bottles of beer on the wall.";</
Using perl5 as a DSL factory leveraging $_'s global nature:
<
#!/usr/bin/env perl
use strict;
Line 6,928 ⟶ 9,696:
, take
, bottles, qq{\n\n}
} for reverse 0..99;</
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">ninetynine</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">99</span> <span style="color: #000080;font-style:italic;">-- (set to 9 for testing)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">bottles</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #008000;">"no more bottles "</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #008000;">"1 bottle "</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">=-</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">ninetynine</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d bottles "</span><span style="color: #0000FF;">,</span><span style="color: #000000;">count</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">bob</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">bottles</span><span style="color: #0000FF;">(</span><span style="color: #000000;">count</span><span style="color: #0000FF;">)&</span><span style="color: #008000;">"of beer"</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">up1</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">bob</span><span style="color: #0000FF;">)</span>
<span style="color: #000080;font-style:italic;">-- Capitalise sentence start (needed just the once, "no more"=>"No more")</span>
<span style="color: #000000;">bob</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">upper</span><span style="color: #0000FF;">(</span><span style="color: #000000;">bob</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">bob</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">many</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">bob</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ninetynine</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">down</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Take one down, pass it around,\n"</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">ninetynine</span> <span style="color: #008080;">to</span> <span style="color: #000000;">0</span> <span style="color: #008080;">by</span> <span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">up1</span><span style="color: #0000FF;">(</span><span style="color: #000000;">many</span><span style="color: #0000FF;">)&</span><span style="color: #008000;">" on the wall,\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">many</span><span style="color: #0000FF;">&</span><span style="color: #008000;">".\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000000;">down</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Go to the store, buy some more,\n"</span>
<span style="color: #008080;">elsif</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span> <span style="color: #000000;">down</span><span style="color: #0000FF;">[</span><span style="color: #000000;">6</span><span style="color: #0000FF;">..</span><span style="color: #000000;">8</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"it"</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">many</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">bob</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">down</span><span style="color: #0000FF;">&</span><span style="color: #000000;">many</span><span style="color: #0000FF;">&</span><span style="color: #008000;">" on the wall.\n\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
=={{header|Phixmonti}}==
<syntaxhighlight lang="phixmonti">def bottles
dup if
"1 bottle" print
else
dup print " bottles" print
endif
else
"No more bottles" print
endif
enddef
def verse
bottles " of beer" print nl
"Take one down, pass it around" print nl
1 - bottles " of beer on the wall" print nl nl
enddef
99 1 -1 3 tolist
for verse . endfor</syntaxhighlight>
With syntactic sugar
<syntaxhighlight lang="phixmonti">include ..\Utilitys.pmt
def bottles
dup 0 == if
"no more bottles of beer"
else
dup 1 == if
"1 bottle of beer"
else
dup tostr " bottles of beer" chain
endif
endif
enddef
( 99 1 -1 ) for
bottles print " on the wall," ?
bottles "," chain ?
"take one
1 - bottles print " on the wall." ? nl
drop
endfor</syntaxhighlight>
=={{header|PHL}}==
Line 7,025 ⟶ 9,781:
{{trans|C}}
<
extern printf;
Line 7,039 ⟶ 9,795:
} while(bottles > 0);
return 0;
]</
=={{header|PHP}}==
<
$plural = 's';
foreach (range(99, 1) as $i) {
Line 7,056 ⟶ 9,812:
echo "No more bottles of beer on the wall!\n";
}
?></
===shorter way===
<
foreach(range(99,1) as $i) {
$p = ($i>1)?"s":"";
Line 7,071 ⟶ 9,827:
}
echo "No more Bottles of beer on the wall";
?></
===Tag syntax===
<syntaxhighlight lang="php"><?php foreach(range(99,1) as $i):?>
<?=$i?> bottle<?=$i==1 ? '' : 's'?> of beer on the wall,
<?=$i?> bottle<?=$i==1 ? '' : 's'?> of beer!
Take one down, pass it around...
<?php if($i > 1):?>
<?=$i-1?> bottle<?=$i==1 ? '' : 's'?> of beer on the wall!
<?php else:?>
No more bottles of beer on the wall!
<?php endif?>
<?php endforeach?></syntaxhighlight>
===modifing way
<
$verse = <<<VERSE
100 bottles of beer on the wall,
Line 7,091 ⟶ 9,860:
echo $verse;
}
?></
===ultra compact alternative===
supports grammar and has no leading and trailing new lines or spaces.
Also one does not have to close the <?php tag, it is even recommended not to close it, if closing it is not necessary
<
for($i=100;$i>0;$i--){
$p2=$i." bottle".(($i>1)?"s":"")." of beer";
Line 7,102 ⟶ 9,871:
$p3="Take one down, pass it around\n";
echo (($i<100)?$p1."\n":"").$p1.$p2."\n".$p3.(($i<2)?($i-1).substr($p1,1,28):"");
}</
===gettext alternative===
supports grammar and translations.
<
$bottles = 99;
Line 7,122 ⟶ 9,891:
}
}
printf('No more bottles of beer on the wall'); //No more bottles of beer on the wall</
===Using printf===
Fun with HEREDOC and printf placeholders
<
$lyrics = <<<ENDVERSE
Line 7,142 ⟶ 9,911:
printf( $lyrics, $x != 1 ? 's' : '', $x--, $x != 1 ? 's' : '', $x > 0 ? $x : 'No more' );
}
</syntaxhighlight>
{{Out}}
Line 7,195 ⟶ 9,964:
=={{header|Picat}}==
<syntaxhighlight lang="picat">
beer1(N) =>
Beer = N,
Line 7,221 ⟶ 9,990:
cond(B > 0, (B-1).to_string() ++ BT ++ BW ++ NL, ""),
S = S1.
</syntaxhighlight>
=={{header|PicoLisp}}==
See [[99 Bottles of Beer/Lisp]]
=={{header|Piet}}==
Line 7,227 ⟶ 9,999:
=={{header|Pike}}==
<
for(int i = 99; i > 0; i--){
write(i + " bottles of beer on the wall, " + i + " bottles of beer.\n");
Line 7,234 ⟶ 10,006:
write("No more bottles of beer on the wall, no more bottles of beer.\n");
write("Go to the store and buy some more, 99 bottles of beer on the wall.\n");
}</
alternate version:
<
void main()
Line 7,260 ⟶ 10,032:
string song = bottles * "take one down, pass it around,\n";
write(song);
}</
=={{header|
El código es de Akira KIDA (SDI00379@niftyserve.or.jp)
<syntaxhighlight lang="pilot">C :bottles = 99
U : *beers
*LOOP
T :$T of beer on the wall, $T.
T :Take one down, pass it around.
C :bottles = bottles - 1
U :*beers
T :$T on the wall.
T :
J(bottles > 0) :*LOOP
END:
*beers
C(bottles = 0) :$T = No more bottles
C(bottles = 1) :$T = 1 bottle
C(bottles > 1) :$T = #bottles bottles
E :</syntaxhighlight>
=={{header|PIR}}==
{{works with|Parrot|Tested with 2.4.0}}
<
.param int b
if b == 1 goto ONE
Line 7,296 ⟶ 10,088:
DRUNK:
end
.end</
=={{header|Plain English}}==
<syntaxhighlight lang="text">
To run:
Start up.
Sing 99 of bottles of beer on the wall.
Wait for the escape key.
Shut down.
To sing a number of bottles of beer on the wall:
Put the number into a counter.
Loop.
Write the first line given the counter.
Write the second line given the counter.
Write "Take one down, pass it around" to the console.
Subtract 1 from the counter.
Write the first line given the counter.
If the counter is 0, break.
Write "" on the console.
Repeat.
To write the first line given a counter:
If the counter is 0, write "No more bottles of beer on the wall" to the console; exit.
If the counter is 1, write "1 bottle of beer on the wall" to the console; exit.
Write the counter then " bottles of beer on the wall" to the console.
To write the second line given a counter:
If the counter is 1, write "1 bottle of beer" to the console; exit.
Write the counter then " bottles of beer" to the console.
</syntaxhighlight>
=={{header|PlainTeX}}==
<
\def\beers{
\par\ifbeer>0 \the\bottles~\else No more \fi
Line 7,321 ⟶ 10,143:
\ifnum\number\bottles>0\repeat
\bye</
=={{header|PL/I}}==
<syntaxhighlight lang="pli">bottles: procedure options(main);
nBottles: procedure(n);
declare n fixed;
if n = 0 then
put skip list('No more bottles');
else if n = 1 then
put skip list('1 bottle');
else do;
if n < 10 then
put skip edit(n) (F(1));
else
put skip edit(n) (F(2));
put list('bottles');
end;
end nBottles;
takeDown: procedure(n);
declare n fixed;
put skip list('Take');
if n=1 then
put list('it');
else
put list('one');
put list('down and take it around,');
end takeDown;
declare n fixed;
do n=99 by -1 to 1;
call nBottles(n);
put list('of beer on the wall,');
call nBottles(n);
put list('of beer,');
call takeDown(n);
call nBottles(n-1);
put list('of beer on the wall.');
put skip;
end;
end bottles;</syntaxhighlight>
=={{header|PL/M}}==
<syntaxhighlight lang="plm">100H: /* CP/M ORIGIN */
BDOS: PROCEDURE(F,PARAM); /* CALL CP/M BDOS */
DECLARE F BYTE;
DECLARE PARAM ADDRESS;
GO TO 5;
END BDOS;
DECLARE BDOS$EXIT LITERALLY '0'; /* BDOS FUNCTIONS */
DECLARE BDOS$PUTS LITERALLY '9';
PRINT$BYTE: PROCEDURE(N); /* PRINT A DECIMAL BYTE */
DECLARE (N, D) BYTE, S (5) BYTE INITIAL ('... $');
DECLARE P ADDRESS, C BASED P BYTE;
P = .S(3);
DIGIT:
P = P - 1;
C = (N MOD 10) + 48;
N = N / 10;
IF N > 0 THEN GO TO DIGIT;
CALL BDOS(BDOS$PUTS, P);
END PRINT$BYTE;
PRINT$STR: PROCEDURE(S); /* PRINT A STRING */
DECLARE S ADDRESS;
CALL BDOS(BDOS$PUTS, S);
END PRINT$STR;
N$OF$BOTTLES: PROCEDURE(N); /* PRINT _N_ BOTTLES */
DECLARE N BYTE;
IF N = 0 THEN CALL PRINT$STR(.('NO MORE$'));
ELSE IF N = 1 THEN CALL PRINT$STR(.('1 BOTTLE$'));
ELSE DO;
CALL PRINT$BYTE(N);
CALL PRINT$STR(.('BOTTLES$'));
END;
END N$OF$BOTTLES;
TAKE$DOWN: PROCEDURE(N); /* PRINT TAKE (ONE/IT) DOWN */
DECLARE N BYTE;
CALL PRINT$STR(.('TAKE $'));
IF N=1 THEN CALL PRINT$STR(.('IT$'));
ELSE CALL PRINT$STR(.('ONE$'));
CALL PRINT$STR(.(' DOWN AND PASS IT AROUND',13,10,'$'));
END TAKE$DOWN;
DECLARE OF$BEER DATA (' OF BEER$');
DECLARE ON$WALL DATA (' ON THE WALL',13,10,'$');
DECLARE NEWLINE DATA (13,10,'$');
DECLARE BOTTLES BYTE INITIAL (99);
DO WHILE BOTTLES > 0;
CALL N$OF$BOTTLES(BOTTLES);
CALL PRINT$STR(.OF$BEER);
CALL PRINT$STR(.ON$WALL);
CALL N$OF$BOTTLES(BOTTLES);
CALL PRINT$STR(.OF$BEER);
CALL PRINT$STR(.NEWLINE);
CALL TAKE$DOWN(BOTTLES);
BOTTLES = BOTTLES - 1;
CALL N$OF$BOTTLES(BOTTLES);
CALL PRINT$STR(.OF$BEER);
CALL PRINT$STR(.ON$WALL);
CALL PRINT$STR(.NEWLINE);
END;
CALL BDOS(BDOS$EXIT,0);
EOF</syntaxhighlight>
=={{header|Pointless}}==
<syntaxhighlight lang="pointless">-----------------------------------------------------------
-- Print the lyrics to the song '99 bottles of beer'
output =
range(99, 1)
|> map(showBeer)
|> printLines
beerFmt = """{} of beer on the wall!
{} of beer!
You take one down, pass it around
{}"""
showBeer(n) =
format(
beerFmt,
[showBottle(n), showBottle(n), nextBeer(n - 1)]
)
nextBeer(n) =
if n == 0 then "No more bottles of beer on the wall!"
else format("{} of beer on the wall!\n", [showBottle(n)])
-----------------------------------------------------------
-- Get appropriate singular / plural form of 'n bottle(s)'
showBottle(n) =
format("{} {}", [n, bottleStr])
where bottleStr = if n == 1 then "bottle" else "bottles"</syntaxhighlight>
=={{header|Pony}}==
=== Recursive ===
<syntaxhighlight lang="pony">actor Main
let _env: Env
new create(env: Env) =>
_env = env
bottles(99)
be bottles(n: U32) =>
if n == 0 then
_env.out.print("No more bottles of beer on the wall, no more bottles of beer.")
_env.out.print("Go to the store and buy some more, 99 bottles of beer on the wall.")
else
if n == 1 then
_env.out.print("1 bottle of beer on the wall, 1 bottle of beer.")
_env.out.print("Take one down and pass it around, no more bottles of beer on the wall.\n")
else
_env.out.print(n.string() + " bottles of beer on the wall, " + n.string() + " bottles of beer.")
_env.out.print("Take one down and pass it around, "+ (n - 1).string() +" bottles of beer on the wall.\n")
end
bottles(n-1)
end</syntaxhighlight>
=== Iterative ===
<syntaxhighlight lang="pony">actor Main
let _env: Env
new create(env: Env) =>
_env = env
var n: I32 = 99
repeat
if n == 0 then
_env.out.print("No more bottles of beer on the wall, no more bottles of beer.")
_env.out.print("Go to the store and buy some more, 99 bottles of beer on the wall.")
elseif n == 1 then
_env.out.print("1 bottle of beer on the wall, 1 bottle of beer.")
_env.out.print("Take one down and pass it around, no more bottles of beer on the wall.\n")
else
_env.out.print(n.string() + " bottles of beer on the wall, " + n.string() + " bottles of beer.")
_env.out.print("Take one down and pass it around, "+ (n - 1).string() +" bottles of beer on the wall.\n")
end
n = n - 1
until n < 0 end</syntaxhighlight>
=={{header|Pop11}}==
<
while n > 0 do
printf(n, '%p bottles of beer on the wall\n');
Line 7,334 ⟶ 10,341:
enddefine;
bootles(99);</
=={{header|PostScript}}==
<syntaxhighlight lang="postscript">%!PS
/Helvetica findfont 9 scalefont setfont
Line 7,373 ⟶ 10,380:
song
showpage
%%EOF</
=={{header|Potion}}==
No extra credit.
<syntaxhighlight lang="potion">99 to 1 (i) :
verse = (n) :
(n, " bottles of beer on the wall\n"
n, " bottles of beer\n"
"Take one down, pass it around\n"
n - 1, " bottles of beer on the wall\n")
.
verse(i) join print
"\n" print
.</syntaxhighlight>
=={{header|PowerShell}}==
Line 7,379 ⟶ 10,402:
=={{header|Processing}}==
'''Console output'''
Immediately prints all output to the console.
<syntaxhighlight lang="processing">for (int i = 99; i > 0; i--) {
print(i + " bottles of beer on the wall\n"
+ i + " bottles of beer\nTake one down, pass it around\n"
+ (i - 1) + " bottles of beer on the wall\n\n");
}</syntaxhighlight>
'''Visual and animated'''
This approach uses Processing's draw loop to display text on the sketch canvas, with a global counter for bottles--draw() is called at the default 60fps, and acts as the for loop. One round of lyrics is displayed at a time, and the counter advances by checking Processing's built-in frameCount. Lyrics may also be advanced manually by clicking the mouse on the canvas.
<syntaxhighlight lang="java">int i = 99;
void setup() {
size(200, 140);
}
void draw() {
background(0);
text(i + " bottles of beer on the wall\n"
+ i + " bottles of beer\nTake one down, pass it around\n"
+ (i-1) + " bottles of beer on the wall\n\n",
10, 20);
if (frameCount%240==239) next(); // auto-advance every 4 secs
}
void mouseReleased() {
next(); // manual advance
}
void next() {
i = max(i-1, 1); // stop decreasing at 1-0 bottles
}
</syntaxhighlight>
==={{header|Processing Python mode}}===
{{trans|Processing}}
<syntaxhighlight lang="python">i = 99
def setup():
size(200, 140)
def draw():
background(0)
text("{} bottles of beer on the wall\n".format(i) +
"{} bottles of beer\n".format(i) +
"Take one down, pass it around\n" +
"{} bottles of beer on the wall\n\n".format(i - 1),
10, 20)
if frameCount % 240 == 239: # auto-advance every 4 secs
next()
def mouseReleased():
next() # manual advance
def next():
global i
i = max(i - 1, 1) # stop decreasing at 1-0 bottles</syntaxhighlight>
==={{header|Processing.R}}===
'''Console output'''
<syntaxhighlight lang="r">setup <- function() {
stdout$print(bottlesong(99))
}
bottlesong <- function(num) {
verses = ""
for(i in num:1){
verses = paste0(verses,
num," bottles of beer on the wall \n",
num," bottles of beer \n",
"Take one down, pass it around \n",
num-1, " bottles of beer on the wall \n\n", sep="");
num <- num - 1
}
return(verses)
}</syntaxhighlight>
=={{header|ProDOS}}==
See [[99 Bottles of Beer/Shell]]
=={{header|Prolog}}==
See [[99 Bottles of Beer/Prolog]]
=={{header|Python}}==
===One line===
{{Works with|Python|3.6+}}
Short, one-line version.
<syntaxhighlight lang="python">
</syntaxhighlight>
===Pythonic version===
{{Works with|Python|3}}
<syntaxhighlight lang="python">
VERSE = '''\
{n} bottle{s} of beer on the wall
{n} bottle{s} of beer
Take one down, pass it around
{n_minus_1} bottle{s2} of beer on the wall
'''
for n in range(99, 0, -1):
if n == 1:
n_minus_1 = 'No more'
s = ''
s2 = 's'
elif n == 2:
n_minus_1 = n - 1;
s = 's'
s2 = ''
else:
n_minus_1 = n - 1;
s = 's'
s2 = 's'
print(VERSE.format(n=n, s=s, s2=s2, n_minus_1=n_minus_1))
</syntaxhighlight>
===
{{Trans|Haskell}}
{{Works with|Python|3.7+}}
<
Line 7,566 ⟶ 10,637:
if __name__ == '__main__':
main()</
===Functional, pythonic version===
{{Works with|Python|3}}
Inspired by [[99_Bottles_of_Beer#Functional|Functional version]]
<syntaxhighlight lang="python">"""
99 Bottles of Beer on the Wall made functional
Main function accepts a number of parameters, so you can specify a name of
the drink, its container and other things. English only.
"""
from functools import partial
from typing import Callable
def regular_plural(noun: str) -> str:
"""English rule to get the plural form of a word"""
if noun[-1] == "s":
return noun + "es"
return noun + "s"
def beer_song(
*,
location: str = 'on the wall',
distribution: str = 'Take one down, pass it around',
solution: str = 'Better go to the store to buy some more!',
container: str = 'bottle',
plurifier: Callable[[str], str] = regular_plural,
liquid: str = "beer",
initial_count: int = 99,
) -> str:
"""
Return the lyrics of the beer song
:param location: initial location of the drink
:param distribution: specifies the process of its distribution
:param solution: what happens when we run out of drinks
:param container: bottle/barrel/flask or other containers
:param plurifier: function converting a word to its plural form
:param liquid: the name of the drink in the given container
:param initial_count: how many containers available initially
"""
verse = partial(
get_verse,
initial_count = initial_count,
location = location,
distribution = distribution,
solution = solution,
container = container,
plurifier = plurifier,
liquid = liquid,
)
verses = map(verse, range(initial_count, -1, -1))
return '\n\n'.join(verses)
def get_verse(
count: int,
*,
initial_count: str,
location: str,
distribution: str,
solution: str,
container: str,
plurifier: Callable[[str], str],
liquid: str,
) -> str:
"""Returns the verse for the given amount of drinks"""
asset = partial(
get_asset,
container = container,
plurifier = plurifier,
liquid = liquid,
)
current_asset = asset(count)
next_number = count - 1 if count else initial_count
next_asset = asset(next_number)
action = distribution if count else solution
inventory = partial(
get_inventory,
location = location,
)
return '\n'.join((
inventory(current_asset),
current_asset,
action,
inventory(next_asset),
))
def get_inventory(
asset: str,
*,
location: str,
) -> str:
"""
Used to return the first or the fourth line of the verse
>>> get_inventory("10 bottles of beer", location="on the wall")
"10 bottles of beer on the wall"
"""
return ' '.join((asset, location))
def get_asset(
count: int,
*,
container: str,
plurifier: Callable[[str], str],
liquid: str,
) -> str:
"""
Quantified asset
>>> get_asset(0, container="jar", plurifier=regular_plural, liquid='milk')
"No more jars of milk"
"""
containers = plurifier(container) if count != 1 else container
spelled_out_quantity = str(count) if count else "No more"
return ' '.join((spelled_out_quantity, containers, "of", liquid))
if __name__ == '__main__':
print(beer_song())
</syntaxhighlight>
{{Out}}
<pre>
>>> print(beer_song(
liquid = 'milk',
location = 'in the fridge',
container = 'jug',
distribution = 'Take one out, pass it around',
initial_count = 2,
))
2 jugs of milk in the fridge
2 jugs of milk
Take one out, pass it around
1 jug of milk in the fridge
1 jug of milk in the fridge
1 jug of milk
Take one out, pass it around
No more jugs of milk in the fridge
No more jugs of milk in the fridge
No more jugs of milk
Better go to the store to buy some more!
2 jugs of milk in the fridge
</pre>
===Flexible, OOP, multiprocessing version (exercise of style)===
{{Works with|Python|3.6+}}
Inspired by the [[99_Bottles_of_Beer#Python_3.2C_functional.2C_pythonic_version|Functional Pythonic Version]]
<syntaxhighlight lang="python">"""
Excercise of style. An overkill for the task :-D
1. OOP, with abstract class and implementation with much common magic methods
2. you can customize:
a. the initial number
b. the name of the item and its plural
c. the string to display when there's no more items
d. the normal action
e. the final action
f. the template used, for foreign languages
3. strofas of the song are created with multiprocessing
4. when you launch it as a script, you can specify an optional parameter for
the number of initial items
"""
from string import Template
from abc import ABC, abstractmethod
from multiprocessing.pool import Pool as ProcPool
from functools import partial
import sys
class Song(ABC):
@abstractmethod
def sing(self):
"""
it must return the song as a text-like object
"""
pass
class MuchItemsSomewhere(Song):
eq_attrs = (
"initial_number",
"zero_items",
"action1",
"action2",
"item",
"items",
"strofa_tpl"
)
hash_attrs = eq_attrs
repr_attrs = eq_attrs
__slots__ = eq_attrs + ("_repr", "_hash")
def __init__(
self,
items = "bottles of beer",
item = "bottle of beer",
where = "on the wall",
initial_number = None,
zero_items = "No more",
action1 = "Take one down, pass it around",
action2 = "Go to the store, buy some more",
template = None,
):
initial_number_true = 99 if initial_number is None else initial_number
try:
is_initial_number_int = (initial_number_true % 1) == 0
except Exception:
is_initial_number_int = False
if not is_initial_number_int:
raise ValueError("`initial_number` parameter must be None or a int-like object")
if initial_number_true < 0:
raise ValueError("`initial_number` parameter must be >=0")
true_tpl = template or """\
$i $items1 $where
$i $items1
$action
$j $items2 $where"""
strofa_tpl_tmp = Template(true_tpl)
strofa_tpl = Template(strofa_tpl_tmp.safe_substitute(where=where))
self.zero_items = zero_items
self.action1 = action1
self.action2 = action2
self.initial_number = initial_number_true
self.item = item
self.items = items
self.strofa_tpl = strofa_tpl
self._hash = None
self._repr = None
def strofa(self, number):
zero_items = self.zero_items
item = self.item
items = self.items
if number == 0:
i = zero_items
action = self.action2
j = self.initial_number
else:
i = number
action = self.action1
j = i - 1
if i == 1:
items1 = item
j = zero_items
else:
items1 = items
if j == 1:
items2 = item
else:
items2 = items
return self.strofa_tpl.substitute(
i = i,
j = j,
action = action,
items1 = items1,
items2 = items2
)
def sing(self):
with ProcPool() as proc_pool:
strofa = self.strofa
initial_number = self.initial_number
args = range(initial_number, -1, -1)
return "\n\n".join(proc_pool.map(strofa, args))
def __copy__(self, *args, **kwargs):
return self
def __deepcopy__(self, *args, **kwargs):
return self
def __eq__(self, other, *args, **kwargs):
if self is other:
return True
getmyattr = partial(getattr, self)
getotherattr = partial(getattr, other)
eq_attrs = self.eq_attrs
for attr in eq_attrs:
val = getmyattr(attr)
try:
val2 = getotherattr(attr)
except Exception:
return False
if attr == "strofa_tpl":
val_true = val.safe_substitute()
val2_true = val.safe_substitute()
else:
val_true = val
val2_true = val
if val_true != val2_true:
return False
return True
def __hash__(self, *args, **kwargs):
_hash = self._hash
if _hash is None:
getmyattr = partial(getattr, self)
attrs = self.hash_attrs
hash_true = self._hash = hash(tuple(map(getmyattr, attrs)))
else:
hash_true = _hash
return hash_true
def __repr__(self, *args, **kwargs):
_repr = self._repr
if _repr is None:
repr_attrs = self.repr_attrs
getmyattr = partial(getattr, self)
attrs = []
for attr in repr_attrs:
val = getmyattr(attr)
if attr == "strofa_tpl":
val_true = val.safe_substitute()
else:
val_true = val
attrs.append(f"{attr}={repr(val_true)}")
repr_true = self._repr = f"{self.__class__.__name__}({', '.join(attrs)})"
else:
repr_true = _repr
return repr_true
def muchBeersOnTheWall(num):
song = MuchItemsSomewhere(initial_number=num)
return song.sing()
def balladOfProgrammer(num):
"""
Prints
"99 Subtle Bugs in Production"
or
"The Ballad of Programmer"
"""
song = MuchItemsSomewhere(
initial_number = num,
items = "subtle bugs",
item = "subtle bug",
where = "in Production",
action1 = "Debug and catch, commit a patch",
action2 = "Release the fixes, wait for some tickets",
zero_items = "Zarro",
)
return song.sing()
def main(num):
print(f"### {num} Bottles of Beers on the Wall ###")
print()
print(muchBeersOnTheWall(num))
print()
print()
print('### "The Ballad of Programmer", by Marco Sulla')
print()
print(balladOfProgrammer(num))
if __name__ == "__main__":
# Ok, argparse is **really** too much
argv = sys.argv
if len(argv) == 1:
num = None
elif len(argv) == 2:
try:
num = int(argv[1])
except Exception:
raise ValueError(
f"{__file__} parameter must be an integer, or can be omitted"
)
else:
raise RuntimeError(f"{__file__} takes one parameter at max")
main(num)
__all__ = (Song.__name__, MuchItemsSomewhere.__name__, muchBeersOnTheWall.__name__, balladOfProgrammer.__name__)
</syntaxhighlight>
=== Other solutions ===
Line 7,572 ⟶ 11,067:
=={{header|Q}}==
<
-1 bobw each reverse 1 + til 99</
=={{header|QB64}}==
----
'''[NOTE]:''' The code below is an amazing, full-on media event! For a simpler version, click [[99_Bottles_of_Beer/Basic#QB64 | HERE.]]
----
<syntaxhighlight lang="qb64">SCREEN _NEWIMAGE(800, 600, 32)
CONST BottleSpeed = 3
PLAY "<"
MakeBottle
Line 7,689 ⟶ 11,185:
_MAPTRIANGLE (0, 0)-(w - 1, 0)-(w - 1, h - 1), Image TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB
</syntaxhighlight>
=={{header|Qore}}==
Line 7,695 ⟶ 11,191:
===Simple Solution===
<
%enable-all-warnings
Line 7,704 ⟶ 11,200:
printf("take one down, pass it around\n");
printf("%d bottles of beer on the wall\n", $i);
}</
===Concurrent (Unordered) Solution===
<
%enable-all-warnings
Line 7,735 ⟶ 11,231:
}
$count.waitForZero();</
=={{header|Quackery}}==
<syntaxhighlight lang="quackery">
[ stack ] is bottles ( --> [ )
[ join carriage join ] is addline ( $ $ --> $ )
[ dup 0 = iff $ 'No more'
else [ dup number$ ]
$ ' bottle' join
swap 1 != if [ char s join ]
$ ' of beer ' join ] is beers ( n --> $ )
$ 'on the wall' is wall ( --> $ )
$ 'Take one down, pass it around'
is drink ( --> $ )
$ 'Go to the store, buy some more'
is restock ( --> $ )
[ dup beers wall addline
over beers addline
over 0 = iff
[ nip bottles share
swap restock ]
else drink addline
swap 1 -
beers wall join addline ] is verse ( n --> $ )
[ 1+ $ '' swap
dup bottles put
times [ i verse addline ]
bottles release ] is song ( n --> $ )
say 'The song "99 Bottles of Beer on the Wall":' cr cr
99 song echo$
</syntaxhighlight>
=={{header|Quill}}==
<
(count > 0) if {
new_count := count - 1;
Line 7,752 ⟶ 11,286:
}
};
99 bottles</
=={{header|Quite BASIC}}==
With grammatical support for "1 bottle of beer"
<syntaxhighlight lang="quite basic">10 let w=" on the wall"
20 for n=99 to 1 step -1
30 let b=" bottles of beer"
40 if n=1 then let b=" bottle of beer"
50 print n;b;w
60 print n;b
70 print "Take one down, pass it around"
80 if n-1=1 then let b=" bottle of beer"
90 if n-1=0 then let b=" bottles of beer"
100 print n-1;b;w
110 next n</syntaxhighlight>
Without grammatical support for "1 bottle of beer"
<syntaxhighlight lang="quite basic">10 let b=" bottles of beer"
20 let w=" on the wall"
30 for n=99 to 1 step -1
40 print n;b;w
50 print n;b
60 print "Take one down, pass it around"
70 print n-1;b;w
80 next n</syntaxhighlight>
=={{header|R}}==
===Simple looping solution===
<
song = function(bottles){
Line 7,772 ⟶ 11,330:
}
song(99)#play the song by calling the function</
===Vector solutions===
<
cat(paste(99:1,ifelse((99:1)!=1," bottles"," bottle")," of beer on the wall\n",99:1,ifelse((99:1)!=1," bottles"," bottle")," of beer\n","Take one down, pass it around\n",98:0,ifelse((98:0)!=1," bottles"," bottle")," of beer on the wall\n\n",sep=""),sep="")
#alternative
cat(paste(lapply(99:1,function(i){paste(paste(rep(paste(i,' bottle',if(i!=1)'s',' of beer',sep=''),2),collapse =' on the wall\n'),'Take one down, pass it around',paste(i-1,' bottle',if(i!=2)'s',' of beer on the wall',sep=''), sep='\n')}),collapse='\n\n'))
#code golf - minimal characters
k=paste0;a=" bottles of beer";o=sub("s","",a);w=" on the wall\n";b=k(a,w);r=k(o,w);t="\nTake one down, pass it around\n";l=99:3;cat(k(l,b,l,a,t,l-1,b),k(2,b,2,a,t,1,r),k(1,r,1,o,t,0,b)) </syntaxhighlight>
=={{header|Ra}}==
<syntaxhighlight lang="ra">
class BottlesOfBeer
**Prints the "99 Bottles of Beer" song"**
Line 7,832 ⟶ 11,393:
if bottle = 1, return "1 bottle"
return "[bottle] bottles"
</syntaxhighlight>
=={{header|Racket}}==
<
#lang racket
(define (sing bottles)
Line 7,844 ⟶ 11,405:
(unless (= 1 bottles) (sing (sub1 bottles))))
(sing 99)
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
=== A Simple Way ===
<syntaxhighlight lang="raku" line>my $b = 99;
repeat while --$b {
say "{b $b} on the wall";
say "{b $b}";
say "Take one down, pass it around";
say "{b $b-1} on the wall";
say "";
}
sub b($b) {
"$b bottle{'s' if $b != 1} of beer";
}</syntaxhighlight>
=== A Clearer Way ===
Similar to "A Simple Way", but with proper variable and subroutine naming, declarator documentation, strongly-typed function definition, better code reuse, and external ternary logic.
<syntaxhighlight lang="raku" line>for 99...1 -> $bottles {
sing $bottles, :wall;
sing $bottles;
say "Take one down, pass it around";
sing $bottles - 1, :wall;
say "";
}
#| Prints a verse about a certain number of beers, possibly on a wall.
sub sing(
Int $number, #= Number of bottles of beer.
Bool :$wall, #= Mention that the beers are on a wall?
) {
my $quantity = $number == 0 ?? "No more" !! $number;
my $plural = $number == 1 ?? "" !! "s";
my $location = $wall ?? " on the wall" !! "";
say "$quantity bottle$plural of beer$location"
}</syntaxhighlight>
=== A More Extravagant Way ===
{{works with|Rakudo|2015.09}}
<syntaxhighlight lang="raku" line>my @quantities = flat (99 ... 1), 'No more', 99;
my @bottles = flat 'bottles' xx 98, 'bottle', 'bottles' xx 2;
my @actions = flat 'Take one down, pass it around' xx 99,
'Go to the store, buy some more';
for @quantities Z @bottles Z @actions Z
@quantities[1 .. *] Z @bottles[1 .. *]
-> ($a, $b, $c, $d, $e) {
say "$a $b of beer on the wall";
say "$a $b of beer";
say $c;
say "$d $e of beer on the wall\n";
}</syntaxhighlight>
=={{header|RapidQ}}==
<syntaxhighlight lang="rapidq">
dim nBott as integer
nBott = 99
Line 7,861 ⟶ 11,481:
while inkey$="":wend
end
</syntaxhighlight>
=={{header|Rascal}}==
<
module demo::basic::Bottles
Line 7,881 ⟶ 11,501:
println("Go to the store and buy some more, 99 bottles of beer on the wall.");
}
</syntaxhighlight>
=={{header|Raven}}==
<
$i 1 = if
"bottle" as $b
Line 7,896 ⟶ 11,516:
else
$i 1 - "%d bottles" format
"%s of beer on the wall.\n\n" print</
{{out}}
Last couple of stanzas are:
Line 7,915 ⟶ 11,535:
=={{header|REBOL}}==
<
Title: "99 Bottles of Beer"
URL: http://rosettacode.org/wiki/99_Bottles_of_Beer
Line 7,933 ⟶ 11,553:
"Take one down, pass it around" crlf
bottles n - 1 "of beer on the wall" crlf
]]</
Output ''(selected highlights)'':
Line 7,952 ⟶ 11,572:
This one prints with proper grammar. "Bottles" changed to "bottle" at the end of the 2 line, and throughout the 1 line. 0 changed to "No" in the last line:
<
x: rejoin [
i b: " bottles of beer" o: " on the wall. " i b
Line 7,960 ⟶ 11,580:
switch i [1 [r x j k r at x 10 j k r x "0" "No"] 2 [r at x 40 j k]]
print x
] halt</
Here's a simple 1 line console version:
<
=={{header|Red}}==
<
Title: "99 Bottles of Beer"
Original-Author: oofoe
Line 7,987 ⟶ 11,607:
"Take one down, pass it around" crlf
bottles n - 1 "of beer on the wall" crlf
]]</
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <Verses 99>>;
};
Verses {
'-'1 = ;
s.1 = <Verse s.1>
<Verses <- s.1 1>>;
};
Verse {
s.1 = <Bottles s.1> ' of beer on the wall,\n'
<Bottles s.1> ' of beer,\n'
<ThirdLine s.1> '\n'
<Bottles <- s.1 1>> ' of beer on the wall!\n\n';
};
Bottles {
'-'1 = '99 bottles';
0 = 'No more bottles';
1 = '1 bottle';
s.1 = s.1 'bottles';
};
ThirdLine {
0 = 'Go to the store and buy some more,';
1 = 'Take it down and pass it around,';
s.1 = 'Take one down and pass it around,';
};</syntaxhighlight>
=={{header|Relation}}==
<syntaxhighlight lang="relation">
program beer(n)
if n>1
echo n." bottles of beer on the wall"
echo n." bottles of beer"
else
echo "1 bottle of beer on the wall"
echo "1 bottle of beer"
end if
echo "Take one down, pass it around"
if n > 2
echo format(n-1,"%1d")." bottles of beer on the wall"
else
echo format(n-1,"%1d")." bottle of beer on the wall"
end if
echo " "
end program
set i = 99
while i > 0
run beer(i)
set i = i-1
end while
</syntaxhighlight>
=={{header|Retro}}==
This is based on the [[Forth]] example.
<
Display the text for the *99 Bottles of Beer* song.
Line 8,019 ⟶ 11,696:
#99 verses
~~~</
=={{header|REXX}}==
Complete with a PSA (<u>P</u>ublic <u>S</u>ervice <u>A</u>nnouncement) comment.
<
parse arg N .; if N=='' | N=="," then N=99 /*allow number of bottles be specified.*/
/* [↓] downward count of beer bottles.*/
Line 8,042 ⟶ 11,719:
exit /*we're all done, and also sloshed !. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
s: if arg(1)=1 then return ''; return 's' /*simple pluralizer for gooder English.*/</
{{out|output|text= Below is the first and last three verses of the song:}}
<pre>
Line 8,082 ⟶ 11,759:
=={{header|Ring}}==
This is a simple solution
<
switch i
on 0
Line 8,103 ⟶ 11,780:
"
off
next</
{{out}}
<pre>
Line 8,129 ⟶ 11,806:
Rockstar solution without special cases for the last 2 verses.
<
Problems are " bottles of beer"
Carol says Take one down, pass it around
Line 8,139 ⟶ 11,816:
Knock the beers down
Say it with Love
</syntaxhighlight>
=={{header|RPG}}==
Line 8,145 ⟶ 11,822:
{{works with|RPGIII|}}
<
F********************************************************************
F*
Line 8,235 ⟶ 11,912:
O 15 'Pass it around'
O E 1 SKIPLN
</syntaxhighlight>
=={{header|RPL}}==
≪ " bottles" " of beer" " on the wall" "Take one down and pass it around,"
→ n b of on take
≪ n 1 '''FOR''' j
j →STR b + of + DUP on + "," + 1 DISP
"," + 2 DISP
take 3 DISP
j 1 ≠ LAST - →STR "No more" IFTE
b +
'''IF''' j 2 == '''THEN''' 1 OVER SIZE 1 - SUB '''END'''
of + on + "." + 4 DISP
-1 '''STEP'''
≫ ≫ '<span style="color:blue">BOB</span>' STO
99 <span style="color:blue">BOB</span>
=={{header|RPL/2}}==
===Simple solution===
<
<<
99 do
Line 8,260 ⟶ 11,952:
<<
" bottle" + over if 1 <> then "s" + end " of beer" +
>></
===Recursive and multithreaded solution===
<
<<
// Child process is started.
Line 8,305 ⟶ 11,997:
RECURSIVE
end
>></
=={{header|Ruby}}==
<
99.downto(1) do |i|
puts "#{i} bottle#{plural} of beer on the wall,"
Line 8,320 ⟶ 12,012:
puts "No more bottles of beer on the wall!"
end
end</
Ruby has variable traces, so we can do
<
$bottles = %Q{#{val == 0 ? 'No more' : val.to_s} bottle#{val == 1 ? '' : 's'}}
end
Line 8,334 ⟶ 12,026:
puts "#{$bottles} of beer on the wall"
puts ""
end</
or...
<
puts "#{of_beer} bottle#{ending} of beer on the wall,"
puts "#{of_beer} bottle#{ending} of beer"
Line 8,350 ⟶ 12,042:
puts "No more bottles of beer on the wall!"
end
end</
or...
<
"#{beer>0 ? beer : "no more"} bottle#{"s" if beer!=1} of beer#{" on the wall" if wall}"
end
Line 8,365 ⟶ 12,057:
end
puts ", #{bottles(remaining-1,true)}.\n\n"
end</
===Simple solution===
<
99.downto(1) do |bottles|
puts "#{bottles} bottle#{"s" if bottles != 1} of beer on the wall.",
Line 8,375 ⟶ 12,067:
"#{bottles - 1} bottle#{"s" if bottles - 1 != 1} of beer on the wall.\n\n"
end
</syntaxhighlight>
=={{header|Rust}}==
===Simple Solution===
<
for n in (0..100).rev() {
match n {
Line 8,397 ⟶ 12,089:
}
}
}</
===Using a trait and impl===
<
fn bottles_of_beer(&self) -> Self;
fn on_the_wall(&self);
Line 8,428 ⟶ 12,120:
println!("-----------------------------------");
}
}</
=={{header|S-BASIC}}==
<
rem - print lyrics to "99 Bottles of Beer on the Wall"
Line 8,491 ⟶ 12,167:
end
</syntaxhighlight>
=={{header|Sather}}==
<syntaxhighlight lang="sather">class MAIN is
main is
s :STR;
p1 ::= "<##> bottle<#> of beer";
w ::= " on the wall";
t ::= "Take one down, pass it around\n";
loop i ::= 99.downto!(0);
if i /= 1 then s := "s" else s := ""; end;
#OUT + #FMT(p1 + w + "\n", i, "s");
#OUT + #FMT(p1 + "\n", i, "s");
if i > 0 then #OUT + t; end;
end;
end;
end;</syntaxhighlight>
=={{header|Scala}}==
See [[99 Bottles of Beer/Scala]]
=={{header|Scheme}}==
<
(define (sing)
(define (sing-to-x n)
Line 8,522 ⟶ 12,203:
(display "would you wanna me to sing it again?")))
(sing-to-x 99))
</syntaxhighlight>
=={{header|Scratch}}==
Line 8,528 ⟶ 12,209:
=={{header|sed}}==
<
h
: b
Line 8,553 ⟶ 12,234:
y/0123456789/9012345678/
h
bb</
=={{header|Seed7}}==
<
const proc: main is func
Line 8,574 ⟶ 12,255:
writeln("No more bottles of beer on the wall, no more bottles of beer.");
writeln("Go to the store and buy some more, 99 bottles of beer on the wall.")
end func;</
=={{header|SenseTalk}}==
Below is a straightforward implementation in SenseTalk. A completely fanciful version (which also works!) can be found here: http://www.99-bottles-of-beer.net/language-sensetalk-1794.html
<syntaxhighlight lang="sensetalk">
set bottleCount to 99
set bottleCount's format to "Words"
repeat while bottleCount is greater than zero
set bottleWord to (if bottleCount is one then "bottle" else "bottles")
put bottleCount && bottleWord && "of beer on the wall,"
put bottleCount && bottleWord && "of beer!"
put "Take one down and pass it around,"
subtract one from bottleCount
set bottleWord to (if bottleCount is one then "bottle" else "bottles")
put bottleCount && bottleWord && "of beer on the wall!"
put empty
end repeat
</syntaxhighlight>
Output:
<syntaxhighlight lang="sensetalk">
Ninety-Nine bottles of beer on the wall,
Ninety-Nine bottles of beer!
Take one down and pass it around,
Ninety-Eight bottles of beer on the wall!
Ninety-Eight bottles of beer on the wall,
Ninety-Eight bottles of beer!
Take one down and pass it around,
Ninety-Seven bottles of beer on the wall!
[...]
Two bottles of beer on the wall,
Two bottles of beer!
Take one down and pass it around,
One bottle of beer on the wall!
One bottle of beer on the wall,
One bottle of beer!
Take one down and pass it around,
Zero bottles of beer on the wall!
</syntaxhighlight>
=={{header|SequenceL}}==
<
import <Utilities/Sequence.sl>;
Line 8,606 ⟶ 12,330:
plural := "s" when num /= 1 else "";
in
count ++ " bottle" ++ plural ++ " of beer";</
=={{header|Set lang}}==
<
set s 32
set m 44
Line 8,705 ⟶ 12,429:
set k 1
set ? 9
> EOF</
=={{header|Shen}}==
See [[99 Bottles of Beer/Lisp]]
=={{header|Shiny}}==
<
s: if i > 1 's' end
Line 8,721 ⟶ 12,448:
say "Take one down, pass it around!"
end
say "Aww...no more bottles of beer on the wall... it must be your shout :)"</
=={{header|Sidef}}==
<
var bottles = "#{i == 0 ? 'No' : i} bottle#{i == 1 ? '' : 's'}"
var sentence = "#{bottles} of beer on the wall" -> say
Line 8,731 ⟶ 12,458:
say "Take one down, pass it around\n"
}
}</
'''Simpler:'''
<
say "#{n} bottles of beer on the wall, #{n} bottles of beer!"
say "Take one down, pass it around, #{n - 1} bottle#{n > 2 ? 's' : ''} of beer on the wall.\n"
Line 8,740 ⟶ 12,467:
say "One bottle of beer on the wall, one bottle of beer!"
say "Take one down, pass it around, no more bottles of beer on the wall."</
=={{header|Simula}}==
<
COMMENT AUTHOR: TIM GOODWIN ;
COMMENT DATE: 04/20/05 ;
Line 8,778 ⟶ 12,506:
BEER(99);
END;
</syntaxhighlight>
'''Simpler:'''
<
author: Jack Leunissen
date: 03/10/07;
Line 8,809 ⟶ 12,537:
OUTIMAGE;
END;
</syntaxhighlight>
=={{header|SkookumScript}}==
<
99.to 1
[
Line 8,821 ⟶ 12,549:
"Take one down, pass it around\n"
bottles(idx-1) " of beer on the wall\n")
]</
=={{header|Slate}}==
<
[| nprinted |
nprinted: n printString ; ' bottle' ; (n > 1 ifTrue: ['s'] ifFalse: ['']) ; ' of beer'.
Line 8,839 ⟶ 12,566:
].
99 bottles.</
=={{header|Slope}}==
<syntaxhighlight lang="scheme">
;; 99 bottles of beer
;;
(define bottles-of-beer (lambda (bottles)
(if (> bottles -1)
(begin0
(for-each
(lambda (app)
(display
(list->string
(cond
((equal? bottles 0)
(list "No more beer"))
((equal? bottles 1)
(list "One bottle of beer"))
(else
(cons bottles " bottles of beer"))) "") app ))
[" on the wall, " "."])
(if (> bottles 0)
(display "\n\tTake one down, pass it around.\n")
(display "\n\tGo to the store and buy some more.\n"))
(bottles-of-beer (- bottles 1))))))
;; main
(bottles-of-beer 99)
</syntaxhighlight>
=={{header|Smalltalk}}==
A straightforward approach:
<
sr := Dictionary new.
sr at: 0 put: ' bottle' ;
Line 8,858 ⟶ 12,610:
Transcript show: (sr at:s) ; show: (sr at:2) ; cr.
(v ~~ 0) ifTrue: [ Transcript show: (sr at:4) ; cr. ].
].</
This version uses Squeak Smalltalk's String >> format: method. and SequencableCollection >> atPin: method
<syntaxhighlight lang="smalltalk">
|bottles plurals |
Transcript clear.
bottles:='{1} bottle{2} of beer on the wall
{1} bottle{2} of beer
Take one down, pass it around
{3} bottle{4} of beer on the wall'.
plurals := #('' 's').
99 to: 1 by: -1 do:[:v |
Transcript show: (bottles format: {(v asString) . (plurals atPin:v) . ((v -1) asString). (plurals atPin:v) }); cr; cr].
Transcript show: 'hic!'; cr.
</syntaxhighlight>
This version uses Squeak Smalltalk's String >> asPluralBasedOn: method to handle the plural and singular cases.
<syntaxhighlight lang="smalltalk">
| bottles |
Transcript clear.
bottles := '{1} {2} of beer on the wall
{1} {2} of beer
Take one down, pass it around
{3} {4} of beer on the wall'.
99 to: 1 by: -1 do: [:i |
Transcript
show: (bottles format: {
i. 'bottle' asPluralBasedOn: i.
i - 1. 'bottle' asPluralBasedOn: i - 1});
cr; cr].
Transcript show: 'hic!'; cr.
</syntaxhighlight>
=={{header|SmileBASIC}}==
Pretty comical version. MML tunes based on QB64 version.
<
IF N==-1 THEN
RETURN "99"
Line 8,910 ⟶ 12,698:
PRINT NUM(I-1);BTL(I-1);" of beer on the wall."
WAITPLAY 131
NEXT</
=={{header|SNOBOL4}}==
<
again output = X " bottles of beer on the wall"
output = X " bottles of beer" ?eq(X,0) :s(zero)
Line 8,920 ⟶ 12,708:
zero output = "Go to store, get some more"
output = "99 bottles of beer on the wall"
end</
===Function===
Line 8,926 ⟶ 12,714:
{{works with|CSnobol}}
Function version with string composition. Function returns one verse for x bottles. Correctly handles bottle/bottles.
<
nl = char(13) char(10) ;* Win/DOS, change as needed
s2 = ' of beer'; s3 = ' on the wall'
Line 8,942 ⟶ 12,730:
n = 2
loop bottles(n); n = gt(n,0) n - 1 :s(loop)
end</
Output:
Line 8,962 ⟶ 12,750:
=={{header|SNUSP}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "bottles" );
pragma annotate( description, "In this puzzle, write code to print out the entire '99 bottles of beer" );
pragma annotate( description, "on the wall' song. A common interview test from Rosetta Code for" );
pragma annotate( description, "testing basic programming skills." );
pragma annotate( author, "Ken O. Burtch" );
pragma license( unrestricted );
pragma restriction( no_external_commands );
procedure Bottles is
begin
for X in reverse 1..99 loop
? strings.image( X ) & " bottles of beer on the wall";
? strings.image( X ) & " bottles of beer";
? "Take one down, pass it around";
? strings.image( integer(X-1) ) & " bottles of beer on the wall" @ "";
end loop;
end Bottles;</syntaxhighlight>
=={{header|Sparkling}}==
<
do {
Line 8,974 ⟶ 12,784:
} while(bottles > 1);
printf("1 bottle of beer on the wall\n1 bottle of beer\nTake it down, pass it around\n0 bottles of beer on the wall\n");</
=={{header|SQL}}==
<syntaxhighlight lang="sql">
select
( 100 - level ) || ' bottle' || case when level != 99 then 's' end || ' of beer on the wall'
Line 8,988 ⟶ 12,798:
|| ( 99 - level ) || ' bottle' || case when level != 98 then 's' end || ' of beer on the wall'
from dual connect by level <= 99;
</syntaxhighlight>
<syntaxhighlight lang="sql">
Line 9,022 ⟶ 12,832:
call bottles_( @bottles, @song);
select @song;
</syntaxhighlight>
This Statement does also work with T-SQL, but only up to 32 beers
<syntaxhighlight lang="sql">
CREATE PROCEDURE bottles
@bottle_count int,
Line 9,074 ⟶ 12,884:
EXECUTE bottles 31, '';
</syntaxhighlight>
<syntaxhighlight lang="sql">
/*These statements work in PostgreSQL (tested in 9.4)*/
Line 9,112 ⟶ 12,922:
ORDER BY n DESC;
</syntaxhighlight>
=={{header|Squirrel}}==
<
function rec(bottles)
{
Line 9,131 ⟶ 12,941:
rec(99);
</syntaxhighlight>
=={{header|Standard ML}}==
<
| bottles x = ( print (Int.toString x ^ " bottles of beer on the wall\n");
print (Int.toString x ^ " bottles of beer\n");
Line 9,140 ⟶ 12,950:
print (Int.toString (x-1) ^ " bottles of beer on the wall\n");
bottles (x-1)
)</
The following code outputs the [https://99-bottles-of-beer.net/lyrics.html full lyrics], generating duplicate text blocks only once.
<syntaxhighlight lang="sml">fun capitalize s =
(str o Char.toUpper o String.sub) (s, 0) ^ String.extract (s, 1, NONE)
fun unfoldN (0, _, _) = []
| unfoldN (n, f, init) =
(fn (item, next) => item :: unfoldN (n - 1, f, next)) (f init)
fun textBlocks 0 = ("no more bottles", "Go to the store and buy some more", 99)
| textBlocks i = (if i = 1 then "1 bottle" else Int.toString i ^ " bottles",
"Take one down and pass it around", i - 1)
fun clauses i =
let
val (f, s, n) = textBlocks i
val f2 = f ^ " of beer"
in
(f2 ^ " on the wall", f2, s, n)
end
fun makeLine l =
concat (ListPair.map op^ (l, [", ", ".\n"]))
fun verse (f1, f2, s, n) =
let
val next as (f1', f2', _, _) = clauses n
in
(makeLine [capitalize f1, f2] ^ makeLine [s, f1'], next)
end
val () = (print o String.concatWith "\n" o unfoldN) (100, verse, clauses 99)</syntaxhighlight>
=={{header|Stata}}==
<
local s s
forvalues i=`1'(-1)0 {
Line 9,184 ⟶ 13,025:
No more bottles of beer
Go to the store and buy some more
2 bottles of beer on the wall...</
=={{header|Suneido}}==
<
while (i > 0)
{
Line 9,197 ⟶ 13,039:
else
Print(i $ ' bottles of beer on the wall\n')
}</
=={{header|SuperCollider}}==
<
(
(99..0).do { |n|
Line 9,229 ⟶ 13,061:
}
)
</syntaxhighlight>
=={{header|SuperTalk}}==
<syntaxhighlight lang="supertalk">-- Rosetta Code problem: https://rosettacode.org/wiki/99_bottles_of_beer
-- by Jjuanhdez, 10/2022
on mouseup
put 99 into numBeerz
put "s it" into modifier
repeat with x = numBeerz down to 1
put "one" into whichone
put "s" into modifier
put "s" into otherModifier
put x - 1 into nextCount
if x is 2 then put "" into otherModifier
if x is 1 then
put "it" into whichone
put "" into modifier
put "s" into otherModifier
put "no more" into nextCount
end if
put x & " bottle" & modifier& " of beer on the wall, " & x & " bottle" &
modifier & " of beer..." after y
put " Take " & whichOne & " down, pass it around, " & nextCount & "
bottle" & otherModifier & " of beer on the wall. " & cr after y
end repeat
put "No more bottles of beer on the wall, ya bastards drank them all! So
off to the store to buy some more, let's put 99 bottles of beer on the
wall!" & cr after y
put y into card field 1
-- say cd fld 1 -- uncomment this line to hear it sing.
end mouseup</syntaxhighlight>
=={{header|Swift}}==
<syntaxhighlight lang="swift">
for i in (1...99).reversed() {
print("\(i) bottles of beer on the wall, \(i) bottles of beer.")
let next = i == 1 ? "no" : (i-1).description
print("Take one down and pass it around, \(next) bottles of beer on the wall.")
}
</syntaxhighlight>
=={{header|Symsyn}}==
<
BBW : ' Bottles of beer on the wall '
TOD : 'Take one down and pass it around '
Line 9,253 ⟶ 13,129:
goif | go back to if
endif
</syntaxhighlight>
=={{header|Tailspin}}==
<
templates sayBottleCount
when <=1> do
'1 bottle' !
when <=0> do
'No bottles' !
otherwise
'$
end sayBottleCount
99..1:-1 ->
'$->sayBottleCount; of beer on the wall,
$->sayBottleCount; of beer.
Take one down, pass it around,
$
' ->
</syntaxhighlight>
{{out}}
<pre>
Line 9,302 ⟶ 13,178:
=={{header|TIScript}}==
<
var beer = 99;
while (beer > 0)
Line 9,311 ⟶ 13,187:
stdout.printf( "%d bottles of beer on the wall\n", --beer );
}
</syntaxhighlight>
=={{header|TMG}}==
Unix TMG:
<syntaxhighlight lang="unixtmg">loop: parse(line1) [--n] parse(line2) [n>=1?]\loop;
line1: beer = { 1 < on the wall, > 1 <.> * };
line2: beer = { <If one of those bottles should happen to fall, > 1 < on the wall.> * };
beer: rest plural = { 2 < bottle> 1 < of beer> };
rest: ( [n>=1?] decimal(n) | = { <no more> } );
plural: ( [n!=1?] = { <s> } | = { } );
n: 143;</syntaxhighlight>
=={{header|TorqueScript}}==
<syntaxhighlight lang="torquescript">
for(%i = 99; %i >= 0; %i--)
{
Line 9,322 ⟶ 13,208:
echo(%n SPC (%i == 1 ? "bottle" : "bottles") SPC "of beer on the wall.");
}
</syntaxhighlight>
=={{header|Transd}}==
<syntaxhighlight lang="Scheme">#lang transd
class MaterialAssets: {
what: (λ (textout quantity " " contents " ")),
consume: (λ (-= quantity 1)),
thereIs: (λ (ret quantity)),
quantity: Int(),
contents: String(),
@init: (λ _q Int(0) _c String()
(= quantity _q) (= contents _c))
}
class Storage: {
where: (λ (textout container)),
container: String(),
@init: (λ _c String() (= container _c))
}
class Activity: {
do: (λ (textout action) (consume stuff)),
provideStuff: (λ _s MaterialAssets() (rebind stuff _s)),
action: String(),
@init: (λ _a String() (= action _a)),
stuff: MaterialAssets()
}
class PartyMaker: {
letsRock: (λ
(while (thereIs stuff)
(what stuff) (where box) (lout "")
(what stuff) (lout "")
(do fun) (lout "")
(what stuff) (where box) (lout "\n"))
(lout "OK! What about one more?")
),
stuff: MaterialAssets(),
box: Storage(),
fun: Activity(),
@init: (λ _s MaterialAssets() _b Storage() _f Activity()
(rebind stuff _s) (rebind box _b) (rebind fun _f)
(provideStuff fun stuff))
}
MainModule: {
_start: (λ
locals: party PartyMaker(
MaterialAssets(99 "bottles of beer")
Storage("on the wall")
Activity("Take one down, pass it around"))
(letsRock party)
)
}</syntaxhighlight>
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
LOOP bottle=1,100
Line 9,341 ⟶ 13,282:
PRINT "Take one down, pass it around"
ENDLOOP
</syntaxhighlight>
=={{header|TXR}}==
Line 9,367 ⟶ 13,288:
The <code>(range 99 -1 -1)</code> expression produces a lazy list of integers from 99 down to -1. The <code>mapcar*</code> function lazily maps these numbers to strings, and the rest of the code treats this lazy list as text stream to process, extracting the numbers with some pattern matching cases and interpolating them into the song's text. Functional programming with lazy semantics meets text processing, pattern matching and here documents.
<
@(collect)
@number
Line 9,398 ⟶ 13,319:
@ (end)
@ (end)
@(end)</
To make the song repeat indefinitely, change the first line to:
<
Now it's processing an infinite lazy lists consisting of
repetitions of the integer sequences 99 98 ... 0.
=={{header|TypeScript}}==
<syntaxhighlight lang="javascript">function beerSong(){
function nbottles(howMany:number){
return `${howMany?howMany:'no'} bottle${howMany!=1?'s':''}`;
}
let song=[];
let beer = 99;
while (beer > 0) {
song.push(`
${nbottles(beer)} of beer on the wall,
${nbottles(beer)} of beer!
Take one down, pass it around
${nbottles(--beer)} of beer on the wall
`);
}
return song.join('');
}
console.log(beerSong());</syntaxhighlight>
=={{header|uBasic/4tH}}==
A very vanilla BASIC implementation.
<syntaxhighlight lang="text">0005 LET I=99
0006 PRINT "Lyrics of the song 99 Bottles of Beer"
Line 9,441 ⟶ 13,382:
0050 REM if equals zero then exit
0051 PRINT "No more bottles of beer on the wall. No more bottles of beer..."
0052 PRINT "Go to the store and buy some more...99 bottles of beer."</syntaxhighlight>
And a more structured version.
<syntaxhighlight lang="text">for n=99 to 2 step -1
print n;" bottles of beer on the wall, ";n;" bottles of beer!"
print "Take one down, pass it around, ";n-1;" bottle";
print show(iif(n>2 , "s", ""));" of beer on the wall.\n"
next
print "One bottle of beer on the wall, one bottle of beer!"
print "Take one down, pass it around, no more bottles of beer on the wall.\n"
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."</syntaxhighlight>
=={{header|UNIX Shell}}==
See [[99 Bottles of Beer/Shell]]
Line 9,448 ⟶ 13,401:
=={{header|UnixPipes}}==
See [[99 Bottles of Beer/Shell]]
=={{header|Unlambda}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|Ursa}}==
<syntaxhighlight lang="text">
#
# 99 bottles of beer
Line 9,475 ⟶ 13,431:
end if
end for
</syntaxhighlight>
=={{header|Ursala}}==
<
# each function takes a natural number to a block of text
Line 9,504 ⟶ 13,460:
#show+
main = whole_song 99</
=={{header|Uxntal}}==
<syntaxhighlight lang="Uxntal">( uxncli 99bottles.rom )
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
|0100 ( -> )
#63 &loop
DUP <print-verse>
[ LIT2 0a -Console/write ] DEO
#01 EQUk ?&done
POP #01 SUB
!&loop
&done BRK
@<print-verse> ( num -- )
DUP <print-bottle> ;dict/wall <print-string>
DUP <print-bottle> [ LIT2 0a -Console/write ] DEO
;dict/take <print-string>
#01 SUB <print-bottle> ;dict/wall !<print-string>
@<print-bottle> ( num -- )
DUP #00 EQU ?&zero
DUP #01 EQU ?&one
<print-dec> ;dict/bottle <print-string>
[ LIT2 "s -Console/write ] DEO
!&end
&one ( num -- )
<print-dec> ;dict/bottle <print-string>
!&end
&zero ( num -- )
POP ;dict/no-more <print-string>
;dict/bottle <print-string>
[ LIT2 "s -Console/write ] DEO
( >> )
&end
;dict/of-beer
( >> )
@<print-string> ( str -- )
&loop
LDAk .Console/write DEO
INC2 LDAk ?&loop
POP2 JMP2r
@<print-dec> ( byte -- )
DUP #64 DIV <print-num>/try
DUP #0a DIV <print-num>/try
( >> )
@<print-num> ( num -- )
#0a DIVk MUL SUB
[ LIT "0 ] ADD .Console/write DEO
JMP2r
&try ( num -- )
DUP ?<print-num>
POP JMP2r
@dict &no-more "No 20 "more $1
&bottle 20 "bottle $1
&of-beer 20 "of 20 "beer 20 $1
&wall "on 20 "the 20 "wall 0a $1
&take "Take 20 "one 20 "down, 20 "pass 20 "it 20 "around 0a $1</syntaxhighlight>
=={{header|UTFool}}==
<syntaxhighlight lang="utfool">
···
http://rosettacode.org/wiki/99_Bottles_of_Beer
Line 9,526 ⟶ 13,547:
s⦂ String: many > 1 ? "s" ! ""
return "⸨many⸩ bottle⸨s⸩ of beer"
</syntaxhighlight>
=={{header|
<
[newline '' puts].
[beer
Line 9,540 ⟶ 13,561:
tailrec].
99 bottles</
=={{header|Vala}}==
<
uint bottles = 99;
do {
Line 9,561 ⟶ 13,582:
print(" of beer on the wall!\n\n");
} while (bottles != 0);
}</
=={{header|VBA}}==
Line 9,568 ⟶ 13,589:
=={{header|VBScript}}==
See [[99 Bottles of Beer/Basic]]
=={{header|Vedit macro language}}==
Most of the keywords in Vedit macro language have both short and long format.
Normally, long format is used here in Rosetta Code for clarity, so here is an example using the short keywords.
<syntaxhighlight lang="vedit">RS(1, " 99")
RS(2, " bottles of beer")
RS(3, " on the wall")
RS(4, " Take one down, pass it around")
#1 = 99
do {
RI(1) RI(2) RI(3) IN
RI(1) RI(2) IN
RI(4) IN
#1-- Num_Str(#1, 1)
RI(1) RI(2) RI(3) IN IN
} while (#1)
Return</syntaxhighlight>
=={{header|Verbexx}}==
<
@LOOP init:{@VAR n = 99} until:(n == 0)
Line 9,579 ⟶ 13,619:
@SAY "Take one down, pass it around" ;
@SAY n (@fb n) "of beer on the wall\n" ;
};</
=={{header|Verilog}}==
<syntaxhighlight lang="verilog">
module beer;
integer i;
initial begin
for (i=4; i>0; i=i-1)
begin
$display("%0d bottles of beer on the wall,", i);
$display("%0d bottles of beer.", i);
$display("Take one down and pass it around,");
if (i==1)
$display("no more bottles of beer on the wall...\n");
else
$display("%0d bottles of beer on the wall...\n", i-1);
end
$display("No more bottles of beer on the wall,\nno more bottles of beer.");
$display("Go to the store and buy some more,\n 99 bottles of beer on the wall.");
end
endmodule
</syntaxhighlight>
=={{header|Visual Prolog}}==
Line 9,586 ⟶ 13,649:
=={{header|Viua VM assembly}}==
<
.function: bottles_of_beer_text/1
.name: %iota number_of_bottles
Line 9,695 ⟶ 13,758:
.end
</syntaxhighlight>
=={{header|V (Vlang)}}==
Fails the task definition for more song, includes the no beer verse.
<syntaxhighlight lang="go">// 99 bottles of V
module main
// pluralize
fn plural(beers int) string {
if beers == 1 { return "" } else { return "s" }
}
// The repetitive song
fn verse(beers int) {
mut beer := beers - 1
mut numno := beers.str()
mut elipsis := ""
if beers == 0 { numno = "No" }
println("$numno bottle${plural(beers)} of beer on the wall")
println("$numno bottle${plural(beers)} of beer")
if beer == 0 { numno = "No" } else { numno = beer.str() }
if beers == 0 {
println("To the store, to buy some more")
numno = "99"
elipsis = "..."
} else {
println("Take one down, pass it around")
}
println("$numno bottle${plural(beer)} of beer on the wall${elipsis}")
}
// passing time
pub fn main() {
for beers := 99; beers >= 0; beers-- {
verse(beers)
println("")
}
}</syntaxhighlight>
=={{header|Vox}}==
<
// translated from <http://rosettacode.org/wiki/99_Bottles_of_Beer#JavaScript>
Line 9,712 ⟶ 13,815:
(beer != 1 ? "s" : "") + " of beer on the wall\n"
);
</syntaxhighlight>
=={{header|VTL-2}}==
<syntaxhighlight lang="vtl2">10 B=99
20 #=200
30 ?=" of beer on the wall,"
40 #=200
50 ?=" of beer,"
60 ?="Take ";
70 #=B=1*100
80 ?="one";
90 #=110
100 ?="it";
110 ?=" down and pass it around,"
120 B=B-1
130 #=200
140 ?=" of beer on the wall!"
150 ?=""
160 #=B=0=0*20
170 #=999
200 ;=!
210 #=B=0*270
220 ?=B
230 ?=" bottle";
240 #=B=1*;
250 ?="s";
260 #=;
270 ?="No more";
280 #=!+10</syntaxhighlight>
=={{header|Wart}}==
Line 9,718 ⟶ 13,849:
=={{header|Whenever}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|Whitespace}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|Wortel}}==
<
0 "0 bottles of beer on the wall\n0 bottles of beer\nbetter go to the store and buy some more."
"{@x} bottle{@?@x{1 @e 's}} of beer on the wall\n{@x} bottle{@?@x{1 @e 's}} of beer\nTake one down, pass it around"
}</
=={{header|Wrapl}}==
<
IMP IO.Terminal USE Out;
Line 9,744 ⟶ 13,878:
Out:write(verse[2,0]@(String.T, "") + verse[1]);
END Bottles.</
=={{header|Wren}}==
<
System.print("%(i) bottles of beer on the wall,")
System.print("%(i) bottles of beer,")
System.print("Take one down, pass it around,")
System.print("%(i - 1) bottles of beer on the wall.\n")
}</
=={{header|X10}}==
<syntaxhighlight lang="x10">public class NinetyNineBottles{
public static def main(args: Rail[String]){
val beerSong: NinetyNineBottles = NinetyNineBottles.make(99);
beerSong.create();
beerSong.sing();
}
var numVerses: Int;
var verses: Array[String]{rank==1};
var bottles: Int;
public static def make(var numBottles: Int){
val s = new NinetyNineBottles();
s.numVerses = numBottles + 1;
val verses: Region{rank==1} = [1..s.numVerses];
s.verses = Array.make[String](verses, (Point) => new String());
s.bottles = numBottles;
return s;
}
public def create(){
finish ateach ( (p):Point in verses ){
val wallCount = bottles - p + 1;
verses(p) = createVerse( p ) ;
}
return;
}
public def sing(){
for ( (p):Point in verses ){
Console.OUT.println(verses(p));
}
return;
}
public def createVerse(var verseNum: Int): String{
val lineA:String,
lineB:String;
val wallCount = bottles - (verseNum - 1);
val nextWallCount = (wallCount + numVerses - 1)%numVerses;
if (wallCount > 0) {
lineA = line(wallCount);
lineB = lineA;
}else{
lineA = "No " + line(wallCount);
lineB = "no " + line(wallCount);
}
return lineA + " on the wall, " + lineB + ".\n" +
action(wallCount) + line(nextWallCount) + " on the wall.\n";
}
public static def line(val numBottles:Int):String{
switch(numBottles){
case 0: return "more bottles of beer";
case 1: return numBottles + " bottle of beer";
default: return numBottles + " bottles of beer";
}
}
public static def action(val numBottles:Int):String{
if (numBottles==0)
return "Go to the store and buy some more, ";
else
return "Take one down and pass it around, ";
}
}</syntaxhighlight>
=={{header|X86 Assembly}}==
See [[99 Bottles of Beer/Assembly]]
=={{header|XBS}}==
<syntaxhighlight lang="xbs">set Bottles = 99;
while (Bottles > 0){
log(Bottles+" bottles of beer on the wall,");
log(Bottles+ " bottles of beer!");
log("Take one down, pass it around");
Bottles-=1;
log(Bottles+" bottles of beer on the wall");
}</syntaxhighlight>
=={{header|xEec}}==
Line 9,762 ⟶ 13,975:
=={{header|Xojo}}==
Place the following in the '''Run''' event handler of a Console application:
<
While bottles > 0
Print(bottles.ToText + " bottles of beer on the wall,")
Line 9,770 ⟶ 13,983:
Print(bottles.ToText + " bottles of beer on the wall.")
Print ""
Wend</
=={{header|XPath}}==
Line 9,788 ⟶ 13,989:
A solution written in pure XPath 3.0 (using XSLT as a host language).
<
<xsl:output method="text"/>
<xsl:template match="/">
Line 9,802 ⟶ 14,003:
/>
</xsl:template>
</xsl:stylesheet></
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">code IntOut=11, Text=12;
int B;
[B:= 99;
repeat IntOut(0, B); Text(0, " bottles of beer on the wall^M^J");
IntOut(0, B); Text(0, " bottles of beer^M^J");
Text(0, "Take one down, pass it around^M^J");
B:= B-1;
IntOut(0, B); Text(0, " bottles of beer on the wall^M^J^J");
until B=0;
]</syntaxhighlight>
=={{header|XSLT}}==
Line 9,809 ⟶ 14,023:
To run, transform any document with this stylesheet (the input document is ignored).
<
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="utf-8"/>
Line 9,882 ⟶ 14,096:
</xsl:template>
</xsl:stylesheet></
===XSLT 3.0===
Line 9,895 ⟶ 14,109:
* use of text value templates (using "{ XPath code }") [first available XSLT 3, see https://www.w3.org/TR/xslt-30/#text-value-templates]
<
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="3.0">
Line 9,914 ⟶ 14,128:
</xsl:iterate>
</xsl:template>
</xsl:stylesheet></
=={{header|xTalk}}==
<syntaxhighlight lang="livecode">
function beerMe numberOfBottles
put "XX bottles of beer on the wall" into verseA
put "Take one down, pass it around" into verseB
repeat with N = numberOfBottles down to 1
put replaceText(verseA,"XX",N) & cr & word 1 to 4 of \
replaceText(verseA,"XX",N) & cr & verseB & cr & replaceText(verseA,"XX",N-1) \
& cr & cr after theSong
end repeat
return theSong
end beerMe
</syntaxhighlight>
=={{header|Yabasic}}==
<
if i=0 return "no more bottles of beer"
if i=1 return "1 bottle of beer"
Line 9,925 ⟶ 14,153:
for i = 99 to 1 step -1
print bottle$(i), " on the wall, \n", bottle$(i), "\n", "take one down, pass it around,\n", bottle$(i - 1), " on the wall.\n"
next</
=={{header|Yacas}}==
<syntaxhighlight lang="yacas">
For (b := 99, b > 0, b--)
Echo({b, "bottle(s) of beer on the wall," : Nl(),
b, "bottle(s) of beer." : Nl(),
"Take one down, pass it around," : Nl(),
b - 1, "bottle(s) of beer on the wall." : Nl()});
</syntaxhighlight>
=={{header|YAMLScript}}==
<syntaxhighlight lang="yaml">
#!/usr/bin/env ys-0
# Print the verses to "99 Bottles of Beer"
#
# usage:
# ys 99-bottles.ys [<count>]
defn main(number=99):
each [n (number .. 1)]:
say: paragraph(n)
defn paragraph(num): |
$bottles(num) of beer on the wall,
$bottles(num) of beer.
Take one down, pass it around.
$bottles(num - 1) of beer on the wall.
defn bottles(n):
cond:
n == 0 : 'No more bottles'
n == 1 : '1 bottle'
=> : "$n bottles"
</syntaxhighlight>
=={{header|Yorick}}==
=== Looped version ===
<
while(bottles) {
write, format=" %d bottles of beer on the wall\n", bottles;
Line 9,936 ⟶ 14,201:
write, "Take one down, pass it around";
write, format=" %d bottles of beer on the wall\n\n", --bottles;
}</
=== Vectorized version ===
<
song += "%d bottles of beer\n";
song += "Take one down, pass it around\n";
song += "%d bottles of beer on the wall\n";
beer = indgen(99:1:-1);
write, format=song, beer, beer, beer-1;</
=={{header|Z80 Assembly}}==
See [[99 Bottles of Beer/Assembly]]
=={{header|Zig}}==
{{trans|C}}
<syntaxhighlight lang="zig">const print = @import("std").debug.print;
pub fn main() void {
var i: u8 = 99;
while (i > 2) : (i-= 1) {
print(
\\{} bottles of beer on the wall, {} bottles of beer.
\\Take one down and pass it around, {} bottles of beer on the wall.
\\
\\
, .{i, i, i-1});
}
print(
\\2 bottles of beer on the wall, 2 bottles of beer.
\\Take one down and pass it around, 1 bottle of beer on the wall.
\\
\\1 bottle of beer on the wall, 1 bottle of beer.
\\Take one down and pass it around, no more bottles of beer on the wall.
\\
\\No more bottles of beer on the wall, no more bottles of beer.
\\Go to the store and buy some more, 99 bottles of beer on the wall.
, .{});
}</syntaxhighlight>
=={{header|zkl}}==
<
println(beers(n), " on the wall, ", beers(n).toLower(), ".\n",
n==0 and ("Go to the store and buy some more, 99 bottles of beer") or
Line 9,960 ⟶ 14,248:
(n==0 and "No more bottles" or (n==1 and "1 bottle" or "" + n + " bottles"))
+ " of beer"
}</
{{out}}
<pre>
|