99 bottles of beer: Difference between revisions

PascalABC.NET
(PascalABC.NET)
 
(209 intermediate revisions by 84 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 &nbsp; '''0''' &nbsp; &nbsp; (zero).
 
Grammatical support for "&nbsp; ''1 bottle of beer"'' &nbsp; is optional.
 
As with any puzzle, try to do it in as creative/concise/comical a way
Line 28:
 
 
{{Template:Strings}}
;Related tasks:
* &nbsp; [[The Twelve Days of Christmas]]
* &nbsp; [[Old_lady_swallowed_a_fly]]
* &nbsp; [[Mad Libs]]
 
 
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}}==
<langsyntaxhighlight lang="forth">
\ 99 bottles of beer on the wall:
: allout "no more bottles" ;
Line 75 ⟶ 87:
 
' beers 1 99 loop- bye
</syntaxhighlight>
</lang>
=={{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}}==
<langsyntaxhighlight ABAPlang="abap">REPORT z99bottles.
 
DATA lv_no_bottles(2) TYPE n VALUE 99.
Line 95 ⟶ 192:
WRITE ' bottles of beer on the wall'.
WRITE /.
ENDDO.</langsyntaxhighlight>
 
or (With ABAP 7.40)
 
<langsyntaxhighlight ABAPlang="abap">REPORT YCL_99_BOTTLES.
 
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>
</lang>
 
=={{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}}==
<langsyntaxhighlight ActionScriptlang="actionscript">for(var numBottles:uint = 99; numBottles > 0; numBottles--)
{
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");
}</langsyntaxhighlight>
 
=={{header|Ada}}==
===Simple version===
<langsyntaxhighlight lang="ada">with Ada.Text_Io; use Ada.Text_Io;
procedure Bottles is
Line 144 ⟶ 320:
New_Line;
end loop;
end Bottles;</langsyntaxhighlight>
===Concurrent version===
with 1 task to print out the information and 99 tasks to specify the number of bottles
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io; use Ada.Text_Io;
 
procedure Tasking_99_Bottles is
Line 185 ⟶ 361:
Task_List(I) := new Counter(I);
end loop;
end Tasking_99_Bottles;</langsyntaxhighlight>
 
=={{header|Aime}}==
<langsyntaxhighlight lang="aime">integer bottles;
 
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);</langsyntaxhighlight>
 
=={{header|Algae}}==
<langsyntaxhighlight lang="algae">
# 99 Bottles of Beer on the Wall
# in Algae
Line 221 ⟶ 397:
}
}
</syntaxhighlight>
</lang>
 
=={{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}} -->
<langsyntaxhighlight lang="algol68">main:(
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
)</langsyntaxhighlight>
 
=={{header|ALGOL-M}}==
<langsyntaxhighlight lang="algol">
BEGIN
 
Line 270 ⟶ 466:
 
END
</syntaxhighlight>
</lang>
 
=={{header|AmigaE}}==
<langsyntaxhighlight lang="amigae">PROC main()
DEF t: PTR TO CHAR,
s: PTR TO CHAR,
Line 285 ⟶ 481:
IF i > 0 THEN WriteF(t)
ENDFOR
ENDPROC</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="xml"><?xml version="1.0"?>
<project name="n bottles" default="99_bottles">
 
Line 330 ⟶ 526:
</target>
 
</project></langsyntaxhighlight>
 
=={{header|Apex}}==
<langsyntaxhighlight lang="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>
</lang>
 
 
=={{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}
 
↑beer¨ ⌽(1-⎕IO)+⍳99
⍝ 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===
 
<langsyntaxhighlight Applescriptlang="applescript">repeat with beerCount from 99 to 1 by -1
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!"</langsyntaxhighlight>
 
 
===Declaration===
<langsyntaxhighlight AppleScriptlang="applescript">-- BRIEF -----------------------------------------------------------------------
on run
set localisations to ¬
Line 497 ⟶ 704:
on unwords(xs)
intercalate(space, xs)
end unwords</langsyntaxhighlight>
 
=={{header|Arbre}}==
<syntaxhighlight lang="arbre">
<lang Arbre>
bottle(x):
template: '
Line 524 ⟶ 731:
bottles(99) -> io
 
</syntaxhighlight>
</lang>
 
 
=={{header|Argile}}==
<langsyntaxhighlight Argilelang="argile">use std
 
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")
}</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
Line 553 ⟶ 759:
=={{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.
<langsyntaxhighlight ArnoldClang="arnoldc">IT'S SHOWTIME
HEY CHRISTMAS TREE is0
YOU SET US UP @NO PROBLEMO
Line 575 ⟶ 781:
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="python">fun bottles(n): match __args__:
(0) => "No more bottles"
(1) => "1 bottle"
Line 589 ⟶ 826:
Take one down, pass it around
{bottles n-1} of beer on the wall\n
"""</langsyntaxhighlight>
 
=={{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">//
<lang ATS>//
#include
"share/atspre_staload.hats"
Line 620 ⟶ 879:
(* ****** ****** *)
 
implement main0 () = bottles (99)</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
Line 634 ⟶ 893:
For example, just a sixpack:
 
<langsyntaxhighlight lang="awk"># usage: gawk -v i=6 -f beersong.awk
 
function bb(n) {
Line 654 ⟶ 913:
}
print "Go to the store and buy some more!"
}</langsyntaxhighlight>
 
{{out}}
Line 691 ⟶ 950:
Pauses are added to accommodate the small calculator screen so all of the text can be read.
 
<langsyntaxhighlight lang="axe">99→B
While B
Disp B▶Dec," BOTTLES OF","BEER ON THE WALL"
Line 700 ⟶ 959:
Disp B▶Dec," BOTTLES OF","BEER ON THE WALL",i
getKeyʳ
End</langsyntaxhighlight>
 
=={{header|Babel}}==
<langsyntaxhighlight lang="babel">-- beer.sp
 
{b " bottles of beer" <
Line 720 ⟶ 979:
< }
 
-- At the prompt, type 'N beer !' (no quotes), where N is the number of stanzas you desire</langsyntaxhighlight>
 
=={{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 728 ⟶ 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 739 ⟶ 1,052:
 
==={{header|FUZE BASIC}}===
See [[99 Bottles of Beer/Basic]]
 
==={{header|GW-BASIC}}===
See [[99 Bottles of Beer/Basic]]
 
Line 748 ⟶ 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 757 ⟶ 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 763 ⟶ 1,094:
 
==={{header|Run BASIC}}===
See [[99 Bottles of Beer/Basic]]
 
==={{header|Sinclair ZX81 BASIC}}===
See [[99 Bottles of Beer/Basic]]
 
Line 772 ⟶ 1,106:
 
==={{header|TI-89 BASIC}}===
See [[99 Bottles of Beer/Basic]]
 
==={{header|Tiny BASIC}}===
See [[99 Bottles of Beer/Basic]]
 
Line 781 ⟶ 1,118:
 
==={{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 792 ⟶ 1,135:
 
<!--- works with C syntax highlighting --->
<syntaxhighlight lang="c">
<lang c>
const bottle = " bottle"
const plural = "s"
Line 936 ⟶ 1,279:
 
// vim: set syntax=c ts=4 sw=4 et:
</syntaxhighlight>
</lang>
 
=={{header|Bc}}==
Line 942 ⟶ 1,285:
{{works with|GNU bc|1.06}}
 
<langsyntaxhighlight Bclang="bc">i = 99;
while ( 1 ) {
print i , " bottles of beer on the wall\n";
Line 955 ⟶ 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</langsyntaxhighlight>
 
=={{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 961 ⟶ 1,338:
Straightforward implementation, displaying the full lyrics given on [ http://99-bottles-of-beer.net/ ]
 
<syntaxhighlight lang="beeswax">
<lang Beeswax>
> NN p
> d#_8~2~(P~3~.~1~>{` bottles of beer on the wall, `{` bottles of beer.`q
Line 970 ⟶ 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>
</lang>
 
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">
<lang Beeswax>
#D@.9~2~@M.7~P9zE `N`p
DMM@.9@.~2~.++~5zE `n`>`o`p
Line 986 ⟶ 1,363:
>^^^^^^^^^; .# b XgNN < bM` ,dnuora ti ssap`<
d^^^^^^^^^^^^^^^^X~3~P(~2~8` ,erom emos yub dna erots eht ot`` oG`<
</syntaxhighlight>
</lang>
 
=={{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.
<langsyntaxhighlight lang="bloop">
DEFINE PROCEDURE ''MINUS'' [A,B]:
BLOCK 0: BEGIN
Line 1,028 ⟶ 1,422:
 
BOTTLES[99];
</syntaxhighlight>
</lang>
 
=={{header|Bracmat}}==
Line 1,042 ⟶ 1,436:
 
Code to save to BottlesOfBeer.bra:
<langsyntaxhighlight lang="bracmat">{BottlesOfBeer.bra
 
See http://99-bottles-of-beer.net/}
Line 1,101 ⟶ 1,495:
 
new'X;
</syntaxhighlight>
</lang>
 
=={{header|Brainf***}}==
Line 1,107 ⟶ 1,501:
 
=={{header|Brat}}==
<langsyntaxhighlight lang="brat">99.to 2 { n |
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,113 ⟶ 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."</langsyntaxhighlight>
 
=={{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 ===
<langsyntaxhighlight lang="c">/*
* 99 Bottles, C, KISS (i.e. keep it simple and straightforward) version
*/
Line 1,145 ⟶ 1,571:
 
return 0;
}</langsyntaxhighlight>
 
=== A recursive solution ===
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int main(int argc, char *argv[])
Line 1,164 ⟶ 1,590:
printf("%d bottle%c of beer on the wall\n\n", argc - 1, (argc - 1) == 1?'\0': 's');
return argc - 1;
}</langsyntaxhighlight>
 
=== Code golf ===
<langsyntaxhighlight lang="c">#include <stdio.h>
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");}</langsyntaxhighlight>
 
=== A preprocessor solution ===
Line 1,179 ⟶ 1,605:
Well, with the preprocessor, that's indeed possible:
 
<langsyntaxhighlight lang="c">#include <stdlib.h>
#include <stdio.h>
 
Line 1,208 ⟶ 1,634:
(void) printf(SONG);
return EXIT_SUCCESS;
}</langsyntaxhighlight>
 
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):<langsyntaxhighlight lang="c"> int b =99,u =1;
#include<stdio.h>
char *d[16],y[]
Line 1,247 ⟶ 1,673:
'S',!(++u % 3) * 32+ 78) or
('.', puts("."))}return c;}
int main() {return p(0);}</langsyntaxhighlight>
 
=={{header|C++}}==
=== The simple solution ===
{{works with|g++|4.8.1}}
<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";
}
}</lang>
 
=== 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:
 
<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;
}</lang>
=== A Recursive solution ===
<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;
}
</lang>
 
=== 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:
 
<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;
}</lang>
 
=== Bottled Version ===
 
<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!!!</lang>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
class Program
Line 1,425 ⟶ 1,704:
}
}
}</langsyntaxhighlight>
 
=== C#6 Implementation ===
{{works with|C sharp|C#|6+}}
<langsyntaxhighlight lang="csharp">using System;
class Program
{
Line 1,439 ⟶ 1,718:
Console.WriteLine($"{f(i, true)}{f(i, false)}Take one down, pass it around\r\n{f(i - 1, true)}");
}
}</langsyntaxhighlight>
 
=== Linq Implementation ===
{{works with|C sharp|C#|36+}}
 
<langsyntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 1,451 ⟶ 1,730:
static void Main()
{
var query = from total in Enumerable.Range(01,100 99).Reverse().Select(x =>
$"{x} bottle{(x == 1 ? "" : "s")} selectof beer on the wall, {x} bottle{(totalx >== 01 ? "" : "s")} of beer!\n" +
$"Take {(x == 1 ? "it" : "one")} down, pass it around, {(x == 1 ? string"no more" : (x - 1).FormatToString("{0))} bottles of beer on the wall!\n{0} bottles of beer\nTake one down, pass it around", total)
).ToList().ForEach(x => Console.WriteLine(x));
: string.Format("{0} bottles left", total);
foreach (var item in query)
{
Console.WriteLine(item);
}
}
}</langsyntaxhighlight>
 
=== Flexible Version ===
<langsyntaxhighlight lang="csharp">using System;
using System.Globalization;
class Program
Line 1,504 ⟶ 1,778:
}
}
}</langsyntaxhighlight>
 
=== Using Formatting ===
{{works with|C sharp|C#|3+}}
 
<langsyntaxhighlight lang="csharp">class songs
{
static void Main(string[] args)
Line 1,536 ⟶ 1,810:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,559 ⟶ 1,833:
{{works with|C sharp|C#|3+}}
 
<langsyntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 1,579 ⟶ 1,853:
yield return String.Format(f, booze(i, true), booze(i, false), booze(i - 1, true));
}
}</langsyntaxhighlight>
 
=== A Fun One ===
<langsyntaxhighlight lang="csharp">string[] bottles = { "80 Shilling",
"Abita Amber",
"Adams Broadside Ale",
Line 1,712 ⟶ 1,986:
Console.WriteLine();
Console.ReadLine();
}</langsyntaxhighlight>
 
=== Using recursion ===
<langsyntaxhighlight lang="csharp">public static void BottlesSong(int numberOfBottles)
{
if (numberOfBottles > 0)
Line 1,726 ⟶ 2,000:
BottlesSong(--numberOfBottles);
}
}</langsyntaxhighlight>
 
=== Using a While Loop ===
<langsyntaxhighlight lang="csharp">static void Main(string[] args)
{
int numBottles = 99;
Line 1,749 ⟶ 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...");
}</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="ceylon">shared void ninetyNineBottles() {
String bottles(Integer count) =>
Line 1,764 ⟶ 2,253:
``bottles(i - 1)`` of beer on the wall!\n");
}
}</langsyntaxhighlight>
 
=={{header|Clay}}==
 
<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)))));
}
</lang>
 
=={{header|Clio}}==
<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'</lang>
 
=={{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">
<lang Chapel>
/***********************************************************************
* Chapel implementation of "99 bottles of beer"
Line 1,875 ⟶ 2,327:
else "Take one down and pass it around, ";
}
</syntaxhighlight>
</lang>
 
=={{header|Chef}}==
See [[99 Bottles of Beer/EsoLang]]
 
 
=={{header|Cind}}==
 
<langsyntaxhighlight lang="cind">
execute() {
 
Line 1,914 ⟶ 2,365:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{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}}==
 
<langsyntaxhighlight lang="clips">(deffacts beer-bottles
(bottles 99))
 
Line 1,936 ⟶ 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)))))</langsyntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight Clojurelang="clojure">(defn paragraph [num]
(str num " bottles of beer on the wall\n"
num " bottles of beer\n"
Line 1,951 ⟶ 2,439:
 
 
(print (lyrics))</langsyntaxhighlight>
 
Or, using cl-format:
{{trans|Common Lisp}}
<langsyntaxhighlight Clojurelang="clojure">(clojure.pprint/cl-format
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))</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="cobol">identification division.
program-id. ninety-nine.
environment division.
Line 2,067 ⟶ 2,592:
 
100-end.
end-program.</langsyntaxhighlight>
 
Another free-form version, without using <code>DISPLAY NO ADVANCING</code>.
<langsyntaxhighlight lang="cobol">identification division.
program-id. ninety-nine.
environment division.
Line 2,191 ⟶ 2,716:
100-end.
end-program.</langsyntaxhighlight>
 
A more concise version that adheres to the minimum guidelines. Leading zeros are not suppressed. (OpenCOBOL - 1.1.0)
<langsyntaxhighlight lang="cobol">program-id. ninety-nine.
data division.
working-storage section.
Line 2,209 ⟶ 2,734:
add 1 to cnt
display space
end-perform.</langsyntaxhighlight>
 
=={{header|CoffeeScript}}==
<langsyntaxhighlight lang="coffeescript">
bottlesOfBeer = (n) ->
"#{n} bottle#{if n is 1 then '' else 's'} of beer"
Line 2,222 ⟶ 2,747:
#{bottlesOfBeer n - 1} on the wall
\n""" for n in [99..1]
</syntaxhighlight>
</lang>
 
With completely different approach...
 
<langsyntaxhighlight lang="coffeescript">for j in [99..1]
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>
</lang>
 
or as a one liner...
 
<langsyntaxhighlight lang="coffeescript">console.log( if (j+2)%4 then (x=Math.round j/4)+" bottle#{if x-1 then 's' else ''} of beer#{if (j+1)%4 then ' on the wall' else ''}" else "Take one down, pass it around" ) for j in [396..1]</langsyntaxhighlight>
 
or another completely different one liner
 
<langsyntaxhighlight lang="coffeescript">((console.log if i is 2 then "Take one down, pass it around" else "#{b-!(i-1%4)} bottle#{if 4*b+i<10 and b-i then '' else 's'} of beer#{if i%3 then ' on the wall' else ''}") for i in [4..1]) for b in [99..1]</langsyntaxhighlight>
 
=={{header|ColdFusion}}==
=== Classic tag based CFML ===
<langsyntaxhighlight lang="cfm"><cfoutput>
<cfloop index="x" from="99" to="0" step="-1">
<cfset plur = iif(x is 1,"",DE("s"))>
Line 2,250 ⟶ 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></langsyntaxhighlight>
or if you prefer: (identical output, grammatically correct to the last stanza)
 
=== CFScript ===
<langsyntaxhighlight lang="cfm"><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></langsyntaxhighlight>
 
=={{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}}==
 
<langsyntaxhighlight lang="cf0x10">bottles = ' bottles '
remaining = 99
one_less_bottle = remaining
Line 2,280 ⟶ 2,830:
 
comefrom if one_less_bottle is 0
'No more bottles of beer on the wall'</langsyntaxhighlight>
 
{{out}}
Line 2,300 ⟶ 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}}==
<langsyntaxhighlight lang="crystal">99.downto(1) do |n|
puts "#{n} bottle#{n > 1 ? "s" : ""} of beer on the wall"
puts "#{n} bottle#{n > 1 ? "s" : ""} of beer"
Line 2,309 ⟶ 3,394:
end
puts "No more bottles of beer on the wall"
</syntaxhighlight>
</lang>
 
=={{header|D}}==
Line 2,318 ⟶ 3,403:
 
Based on Steward Gordon's code at: [http://99-bottles-of-beer.net/language-d-721.html 99-bottles-of-beer.net].
<langsyntaxhighlight lang="d">import std.stdio;
 
void main() {
Line 2,337 ⟶ 3,422:
writeln("Go to the store and buy some more,");
writeln("99 bottles of beer on the wall.");
}</langsyntaxhighlight>
 
=== CTFE Solution ===
Line 2,343 ⟶ 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.
 
<langsyntaxhighlight lang="d">import std.stdio, std.conv;
 
string bottles(in size_t num) pure {
Line 2,366 ⟶ 3,451:
 
pragma(msg, 99.bottles);
void main() {}</langsyntaxhighlight>
 
=== Template Meta-Programming Solution ===
Line 2,372 ⟶ 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">
<lang d>
module bottles;
 
Line 2,394 ⟶ 3,479:
 
void main(){}
</syntaxhighlight>
</lang>
 
=={{header|Dart}}==
// Making use of polymorphism
<lang dart>main() {
<syntaxhighlight lang="dart">main() {
for(int x=99;x>0;x--) {
BeerSong beerSong = BeerSong();
print("$x bottles of beer on the wall");
//pass a 'starting point' and 'end point' as parameters respectively
print("$x bottles of beer");
String printTheLyrics = beerSong.recite(99, 1).join('\n');
print("Take one down, pass it around");
print("${x-1} bottles of beer on the wall"printTheLyrics);
print("");
}
 
}</lang>
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,411 ⟶ 3,549:
{{works with|GNU dc}}
{{works with|OpenBSD dc}}
<syntaxhighlight lang="dc">[
<lang Dc>[
dnrpr
dnlBP
Line 2,439 ⟶ 3,577:
]P
[no more bottles of beer on the wall
]P</langsyntaxhighlight>
 
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">[
<lang Dc>[
plAP
plBP
Line 2,475 ⟶ 3,613:
]P
[no more bottles of beer on the wall
]P</langsyntaxhighlight>
 
 
=={{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}}==
<langsyntaxhighlight lang="dejavu">plural i:
if = 1 i "" "s"
 
Line 2,497 ⟶ 3,733:
!print "Go to the store and buy some more, 99 bottles of beer on the wall."
 
bottles 99</langsyntaxhighlight>
 
=={{header|DyalectDIBOL-11}}==
<syntaxhighlight lang="dibol-11">
{{trans|Swift}}
;
<lang dyalect>for i in 99..1 {
;===============================================================================
print("\(i) bottles of beer on the wall, \(i) bottles of beer.")
========================
const next = if i == 1 {
; Oringinal Author: Bob Welton (welton@pui.com)
"no"
; Language: DIBOL or DBL
} else {
;
(i - 1).toString()
; Modified to work with DEC DIBOL-11
}
; by Bill Gunshannon
print("Take one down and pass it around, \(next) bottles of beer on the wall.")
;===============================================================================
}</lang>
========================
 
RECORD MISC
=={{header|Dylan}}==
NUMBOTTLES ,D2,99 ;Default # of bottles to 99
<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</lang>
 
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}}==
<langsyntaxhighlight lang="e">def bottles(n) {
return switch (n) {
match ==0 { "No bottles" }
Line 2,537 ⟶ 3,825:
${bottles(n.previous())} of beer on the wall.
`)
}</langsyntaxhighlight>
 
=={{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">
<lang ECL>
Layout := RECORD
UNSIGNED1 RecID1;
Line 2,563 ⟶ 3,873:
Rev := NORMALIZE(Beers,5,XF(LEFT,COUNTER));
OUTPUT(SORT(Rev,-Recid1,-RecID2),{txt},ALL);
</syntaxhighlight>
</lang>
 
=={{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">
<lang Egel>
import "prelude.eg"
import "io.ego"
Line 2,583 ⟶ 3,911:
 
def main = print_rhyme 99
</syntaxhighlight>
</lang>
 
=={{header|EGL}}==
<langsyntaxhighlight EGLlang="egl">program TestProgram type BasicProgram {}
function main()
Line 2,607 ⟶ 3,935:
end
end
end</langsyntaxhighlight>
 
=={{header|Eiffel}}==
<langsyntaxhighlight lang="eiffel">
class
APPLICATION
Line 2,651 ⟶ 3,979:
 
end
</syntaxhighlight>
</lang>
 
An alternative version written using the across-loop construct.
<langsyntaxhighlight lang="eiffel">
output_lyrics
-- Output the lyrics to 99-bottles-of-beer.
Line 2,678 ⟶ 4,006:
end
 
</syntaxhighlight>
</lang>
 
=={{header|Ela}}==
 
<langsyntaxhighlight Elalang="ela">open list
beer 1 = "1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around"
Line 2,690 ⟶ 4,018:
++" bottles of beer\nTake one down, pass it around\n"
map beer [99,98..0]</langsyntaxhighlight>
 
=={{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 56.0 :
<langsyntaxhighlight lang="elena">import system'routines;
import extensions;
import extensions'routines;
Line 2,704 ⟶ 4,093:
= self.toPrintable() + (self != 1).iif(" bottles"," bottle");
bottleEnumerator() = new Variable(self).doWith::(n)
{
^ new Enumerator
Line 2,710 ⟶ 4,099:
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:(1)).bottleDescription()," of beer on the wall");
reset() {}
enumerable() = __targetweak self;
}
};
Line 2,727 ⟶ 4,116:
var bottles := 99;
bottles.bottleEnumerator().forEach:(printingLn)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,756 ⟶ 4,145:
0 bottles of beer on the wall
</pre>
 
=={{header|Emacs Lisp}}==
<lang Lisp> (let ((i 99))
(while (> i 0)
(princ-list i " bottles of beer on the wall" "\n Take one down, pass it around")
(setq i (1- i))))</lang>
 
=={{header|Elixir}}==
<langsyntaxhighlight Elixirlang="elixir">defmodule Bottles do
def run do
Enum.each 99..1, fn idx ->
Line 2,779 ⟶ 4,162:
end
 
Bottles.run</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="erlang">-module(beersong).
-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,820 ⟶ 4,295:
spawn_singer(Bottle),
sing_verse(Bottle)
end.</langsyntaxhighlight>
 
=={{header|Euphoria}}==
{{works with|Euphoria|4.0.0}}
<syntaxhighlight lang="euphoria">constant
<lang Euphoria>
constant
bottles = "bottles",
bottle = "bottle"
Line 2,852 ⟶ 4,326:
for a = 99 to 1 by -1 do
beers (a)
end for</syntaxhighlight>
</lang>
 
<lang Euphoria>
 
<syntaxhighlight lang="euphoria">-- An alternate version
 
include std/console.e
Line 2,873 ⟶ 4,344:
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
</lang>
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,881 ⟶ 4,371:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">#light
let rec bottles n =
let (before, after) = match n with
Line 2,892 ⟶ 4,382:
printfn "%d %s of beer on the wall\n" (n - 1) after
if n > 1 then
bottles (n - 1)</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: io kernel make math math.parser math.ranges sequences ;
 
: bottle ( -- quot )
Line 2,916 ⟶ 4,406:
1 [a,b] bottle each last-verse ;
 
! Usage: 99 bottles</langsyntaxhighlight>
 
=={{header|Falcon}}==
<langsyntaxhighlight lang="falcon">for i in [99:1]
> 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</langsyntaxhighlight>
 
A more robust version to handle plural/not plural conditions
<langsyntaxhighlight lang="falcon">for i in [99:1]
plural = (i != 1) ? 's' : ""
> @ "$i bottle$plural of beer on the wall"
Line 2,933 ⟶ 4,423:
> "Take one down, pass it around"
> i-1, @ " bottle$plural of beer on the wall\n"
end</langsyntaxhighlight>
 
=={{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].
 
<langsyntaxhighlight lang="ferite">uses "console";
 
number bottles = 99;
Line 2,960 ⟶ 4,461:
looping = counter.invoke();
Console.println("${bottles} bottles of beer on the wall.");</langsyntaxhighlight>
 
=={{header|Fexl}}==
<langsyntaxhighlight lang="fexl">
\suffix=(\n eq n 1 "" "s")
\sing_count=(\n put [n " bottle" (suffix n) " of beer"])
Line 2,980 ⟶ 4,481:
)
sing 3
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,000 ⟶ 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}}==
<langsyntaxhighlight lang="forth">:noname dup . ." bottles" ;
:noname ." 1 bottle" ;
:noname ." no more bottles" ;
Line 3,015 ⟶ 4,564:
: verses begin cr .verse ?dup 0= until ;
 
99 verses</langsyntaxhighlight>
 
Version 2: create a beer language and write the program
<langsyntaxhighlight lang="forth">DECIMAL
: BOTTLES ( n -- )
DUP
Line 3,052 ⟶ 4,601:
ONELESS BOTTLES OF BEER ON THE WALL .
ANOTHER
HANGOVER ;</langsyntaxhighlight>
 
Forth Console Output
<langsyntaxhighlight Forthlang="forth">2 beers
2 bottles of beer on the wall,
2 bottles of beer ,
Line 3,066 ⟶ 4,615:
No more bottles of beer on the wall.
 
ok</langsyntaxhighlight>
 
=={{header|Fortran}}==
===F90 version===
<langsyntaxhighlight lang="fortran">program bottlestest
 
implicit none
Line 3,093 ⟶ 4,642:
end do
 
end program bottlestest</langsyntaxhighlight>
 
===MPI version===
<langsyntaxhighlight lang="fortran">program bottlesMPI
 
implicit none
Line 3,123 ⟶ 4,672:
call mpi_finalize(ierr)
 
end program bottlesMPI</langsyntaxhighlight>
 
Usage:
Line 3,131 ⟶ 4,680:
===Fortran 2003/2008 OOP version===
Works with GNU gfortran 5.0.0 and Intel ifort 15.0.2
<langsyntaxhighlight lang="fortran">
module song_typedefs
implicit none
Line 3,264 ⟶ 4,813:
 
end program bottles_song
</syntaxhighlight>
</lang>
 
=={{header|Frege}}==
Line 3,271 ⟶ 4,820:
{{Works with|Frege|3.21.586-g026e8d7}}
 
<langsyntaxhighlight lang="frege">module Beer where
 
main = mapM_ (putStrLn . beer) [99, 98 .. 0]
Line 3,279 ⟶ 4,828:
++ show v
++ " bottles of beer\nTake one down, pass it around\n"
++ head (lines $ beer $ v-1) ++ "\n"</langsyntaxhighlight>
 
=={{header|friendly interactive shell}}==
Line 3,286 ⟶ 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.
<langsyntaxhighlight lang="frink">
units = array[units[volume]]
showApproximations[false]
Line 3,304 ⟶ 4,853:
 
getBottleString[n, unit] := format[n*12 floz, unit, 6] + "s"
</syntaxhighlight>
</lang>
 
Sample randomized output:
Line 3,343 ⟶ 4,892:
 
=={{header|FunL}}==
<langsyntaxhighlight lang="funl">val
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,372 ⟶ 4,921:
+ ' of beer on the wall.\n')
 
for i <- 99..0 by -1 do println( verse(i) )</langsyntaxhighlight>
 
=={{header|FutureBasic}}==
<langsyntaxhighlight lang="futurebasic">
include "ConsoleWindowNSLog.incl"
 
NSUInteger i
dim as short 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 )
print i; " bottles of beer on the wall,"
print i; " bottles of beer."
print
print "Take one down, pass it around,"
print i-1; " bottles of beer on the wall."
print
next
</lang>
 
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}}==
<langsyntaxhighlight lang="gap">Bottles := function(n)
local line, i, j, u;
line := function(n)
Line 3,413 ⟶ 5,004:
fi;
od;
end;</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="genie">[indent=4]
def plural(n:uint):string
return (n == 1) ? "" : "s"
Line 3,429 ⟶ 5,084:
--bottles
print "%s bottle%s of beer on the wall\n", no(bottles), plural(bottles)
while bottles != 0</langsyntaxhighlight>
 
{{out}}
Line 3,445 ⟶ 5,100:
 
=={{header|gnuplot}}==
<langsyntaxhighlight lang="gnuplot">if (!exists("bottles")) bottles = 99
print sprintf("%i bottles of beer on the wall", bottles)
print sprintf("%i bottles of beer", bottles)
Line 3,452 ⟶ 5,107:
print sprintf("%i bottles of beer on the wall", bottles)
print ""
if (bottles > 0) reread</langsyntaxhighlight>
 
=={{header|Go}}==
===No sense of humor===
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 3,478 ⟶ 5,133:
fmt.Printf("%s of beer on the wall\n", bottles(i-1))
}
}</langsyntaxhighlight>
 
===Typoglycemic===
With code from RC tasks Number names, Knuth shuffle.
<langsyntaxhighlight lang="go">package main
 
import (
Line 3,561 ⟶ 5,216:
w := strings.Fields(p[:1] + string(a) + p[len(p)-1:])
return strings.Join(w, " ")
}</langsyntaxhighlight>
{{out}}
Things start out pretty well...
Line 3,603 ⟶ 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.
<langsyntaxhighlight lang="go!">--
-- 99 Bottles of Beer in Go!
-- John Knottenbelt
Line 3,633 ⟶ 5,288:
bottles(1) => "1 bottle of beer".
bottles(i) => i^0 <> " bottles of beer".
}</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="golo">module Bottles
 
augment java.lang.Integer {
Line 3,654 ⟶ 5,312:
println("--------------------------------------")
})
}</langsyntaxhighlight>
 
=={{header|Gosu}}==
<langsyntaxhighlight lang="gosu">
for (i in 99..0) {
 
Line 3,669 ⟶ 5,327:
 
}
</syntaxhighlight>
</lang>
 
=={{header|Golfscript}}==
<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</lang>
 
=={{header|Groovy}}==
===Basic Solution===
With a closure to handle special cardinalities of bottles.
<langsyntaxhighlight lang="groovy">def bottles = { "${it==0 ? 'No more' : it} bottle${it==1 ? '' : 's' }" }
 
99.downto(1) { i ->
Line 3,686 ⟶ 5,341:
${bottles(i-1)} of beer on the wall
"""
}</langsyntaxhighlight>
 
=== Single Print Version ===
Uses a single print algorithm for all four lines. Handles cardinality on bottles, uses 'No more' instead of 0.
<langsyntaxhighlight lang="groovy">298.downto(2) {
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"
}</langsyntaxhighlight>
 
===Bottomless Beer Solution===
Using more closures to create a richer lyrical experience.
<langsyntaxhighlight lang="groovy">def bottles = { "${it==0 ? 'No more' : it} bottle${it==1 ? '' : 's' }" }
 
def initialState = {
Line 3,727 ⟶ 5,382:
}
// Thread.sleep(1000)
// }</langsyntaxhighlight>
 
=={{header|GUISS}}==
Line 3,733 ⟶ 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:
 
<langsyntaxhighlight lang="guiss">Start,Programs,Accessories,Calculator,Button:9,Button:9,
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>
</lang>
We haven't drank all of the bottles at this point, but we can keep going, if we want.
 
=={{header|GW-BASIC}}==
 
Just a basic loop counting down to one. No big deal. Note that at BOTTLES=1, it is not
grammatically correct.
 
<lang qbasic>10 FOR BOTTLES = 99 TO 1 STEP -1
20 PRINT BOTTLES " bottles of beer on the wall"
30 PRINT BOTTLES " bottles of beer"
40 PRINT "Take one down, pass it around"
50 PRINT BOTTLES-1 " bottles of beer on the wall"
60 NEXT BOTTLES
</lang>
 
=={{header|Halon}}==
<langsyntaxhighlight lang="halon">$plural = "s";
$x = 99;
while ($x > 0) {
Line 3,768 ⟶ 5,410:
else
echo "No more bottles of beer on the wall!";
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
Line 3,774 ⟶ 5,416:
A relatively concise solution:
 
<langsyntaxhighlight lang="haskell">main = mapM_ (putStrLn . beer) [99, 98 .. 0]
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,780 ⟶ 5,422:
++ show v
++" bottles of beer\nTake one down, pass it around\n"
++ head (lines $ beer $ v-1) ++ "\n"</langsyntaxhighlight>
====List comprehension====
As a list comprehension:
 
<langsyntaxhighlight lang="haskell">import qualified Char
 
main = putStr $ concat
Line 3,799 ⟶ 5,441:
num n = show n
s 1 = ""
s _ = "s"</langsyntaxhighlight>
 
====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.
 
<langsyntaxhighlight lang="haskell">{-# LANGUAGE TemplateHaskell #-}
-- build with "ghc --make beer.hs"
module Main where
Line 3,831 ⟶ 5,473:
in return $ LitE $ StringL $ song)
 
main = putStr songString</langsyntaxhighlight>
 
====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.
<langsyntaxhighlight lang="haskell">location, distribution, solution :: String
[location, distribution, solution] =
[ "on the wall",
, "Take one down, pass it around",
, "Better go to the store to buy some more"
]
 
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,848 ⟶ 5,504:
| 1 == n = []
| otherwise = ['s']
in unwords
in unwords [show n, (reverse . concat) $ suffix n : ["elttob"]]
[show n, (reverse . concat) $ suffix n : ["elttob"]]
 
incantation :: Int -> String
incantation n =
let inventory = unwords . (: [location]) . asset
in case n of
0 -> solution
_ -> unlines [inventory n, asset n, distribution, inventory $ pred n]
 
main :: IO ()
main = putStrLn $ unlines (incantation <$> [99, 98 .. 0])</langsyntaxhighlight>
 
=={{header|Haxe}}==
=== Simple solution ===
<langsyntaxhighlight lang="haxe">class RosettaDemo
{
static public function main()
Line 3,894 ⟶ 5,544:
}
}
}</langsyntaxhighlight>
 
=== Macro solution ===
Line 3,900 ⟶ 5,550:
Let's generate that print with macro.
 
<langsyntaxhighlight lang="haxe">class Bottles {
 
static public function main () : Void {
Line 3,932 ⟶ 5,582:
}
 
}</langsyntaxhighlight>
 
=={{header|hexiscript}}==
<langsyntaxhighlight lang="hexiscript">fun bottles amount beverage location
let bottle " bottles of "
if amount = 0; let amount "No more"
Line 3,956 ⟶ 5,606:
println take "one" "down" + pass "it" "around"
println bottles (--amount) "beer" "on the wall\n"
endwhile</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">DO x = 99, 1, -1
WRITE() x , "bottles of beer on the wall"
BEEP("T16 be be be bH bH bH be be be 2be ")
Line 3,971 ⟶ 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</langsyntaxhighlight>
 
=={{header|HQ9+HolyC}}==
See [[99 Bottles of Beer/EsoLang]]
 
=={{header|Huginn}}==
<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 );
}</lang>
 
=={{Header|HolyC}}==
The default is 99 bottles, but it can be modified by the parameter.
 
<langsyntaxhighlight lang="holyc">U0 BottlesOfBeer (I64 initial=99) {
// This is made I64 rather than U64
// Because, a U64 would overflow
Line 4,034 ⟶ 5,655:
// Calls the function, which goes to the default parameters
BottlesOfBeer;
</syntaxhighlight>
</lang>
 
=={{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...
<langsyntaxhighlight lang="icon">procedure main(args)
numBeers := integer(args[1]) | 99
drinkUp(numBeers)
Line 4,065 ⟶ 5,822:
write("Go to the store and buy some more, ",
beerMax," bottles of beer on the wall.")
end</langsyntaxhighlight>
 
=={{header|IDL}}==
<langsyntaxhighlight IDLlang="idl">Pro bottles
 
for i=1,99 do begin
Line 4,077 ⟶ 5,834:
End
 
</syntaxhighlight>
</lang>
 
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:
 
<langsyntaxhighlight IDLlang="idl">Pro bottles_noloop
b=(reverse(shift(sindgen(100),-1)))[1:99]
b2=reverse(sindgen(99))
Line 4,088 ⟶ 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</langsyntaxhighlight>
 
I found the above example very helpful but overdone. This is a more simple version:
 
<langsyntaxhighlight IDLlang="idl">Pro bottles_noloop2
n_bottles=99
b1 = reverse(SINDGEN(n_bottles,START=1))
Line 4,100 ⟶ 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</langsyntaxhighlight>
 
=={{header|Idris}}==
<syntaxhighlight lang="idris">
<lang Idris>
beerSong : Fin 100 -> String
beerSong x = verses x where
Line 4,123 ⟶ 5,880:
verses fZ = ""
verses (fS n) = (verse (fS n)) ++ (verses n)
</syntaxhighlight>
</lang>
 
=={{header|Inform 6}}==
<langsyntaxhighlight lang="inform6">[ Bottles i;
if(i == 1) return "bottle";
 
Line 4,145 ⟶ 5,902:
Beer(99);
];
</syntaxhighlight>
</lang>
 
=={{header|Inform 7}}==
=== Programmatic solution ===
<langsyntaxhighlight lang="inform7">Beer Hall is a room.
 
When play begins:
Line 4,158 ⟶ 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.</langsyntaxhighlight>
 
=== World model solution ===
This solution uses in-game objects to represent the wall and the bottles.
 
<langsyntaxhighlight lang="inform7">Beer Hall is a room.
 
The plural of bottle of beer is bottles of beer. A bottle of beer is a kind of thing.
Line 4,180 ⟶ 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".</langsyntaxhighlight>
 
=={{header|Intercal}}==
See [[99 Bottles of Beer/EsoLang]]
 
=={{header|Io}}==
<langsyntaxhighlight lang="io">bottles := method(i,
if(i==0, return "no more bottles of beer")
if(i==1, return "1 bottle of beer")
Line 4,198 ⟶ 5,952:
bottles(i - 1), " on the wall.\n\n"
)
)</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="ioke">bottle = method(i,
case(i,
0, "no more bottles of beer",
Line 4,211 ⟶ 6,268:
"take one down, pass it around," println
"#{bottle(i - 1)} on the wall.\n" println
)</langsyntaxhighlight>
 
=={{header|J}}==
As posted at the [http://www.jsoftware.com/jwiki/Essays/99_Bottles_of_Beer J wiki]
<langsyntaxhighlight lang="j">bob =: ": , ' bottle' , (1 = ]) }. 's of beer'"_
bobw=: bob , ' on the wall'"_
beer=: bobw , ', ' , bob , '; take one down and pass it around, ' , bobw@<:
beer"0 >:i.-99</langsyntaxhighlight>
 
{{Out}}
Line 4,227 ⟶ 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.
<langsyntaxhighlight lang="java">import java.text.MessageFormat;
 
public class Beer {
Line 4,249 ⟶ 6,345:
}
}
}</langsyntaxhighlight>
 
'''Optimized for speed and few I/O operations'''
<langsyntaxhighlight lang="java">public class Beer {
public static void main(String[] args) {
int bottles = 99;
Line 4,265 ⟶ 6,361:
System.out.println(sb.append(verse3));
}
}</langsyntaxhighlight>
 
'''Recursive'''
<langsyntaxhighlight lang="java">public class Beer {
public static void main(String args[]) {
song(99);
Line 4,284 ⟶ 6,380:
}
}
}</langsyntaxhighlight>
 
=== An object-oriented solution ===
Line 4,295 ⟶ 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.
<langsyntaxhighlight lang="java">import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
Line 4,335 ⟶ 6,431:
}
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
===ES3-5===
<langsyntaxhighlight lang="javascript">var beer = 99;
while (beer > 0) {
var verse = [
Line 4,352 ⟶ 6,448:
beer--;
}
</syntaxhighlight>
</lang>
 
===ES6===
<langsyntaxhighlight lang="javascript">let beer = 99;
while (beer > 0) {
let verse = `${beer} bottles of beer on the wall,
Line 4,364 ⟶ 6,460:
console.log(verse);
beer--;
}</langsyntaxhighlight>
 
===Functional / Recursive===
<langsyntaxhighlight lang="javascript">var bottles = 99;
var songTemplate = "{X} bottles of beer on the wall \n" +
"{X} bottles of beer \n"+
Line 4,377 ⟶ 6,473:
}
 
console.log(song(bottles, songTemplate));</langsyntaxhighlight>
 
===Other Examples===
Line 4,383 ⟶ 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".
<langsyntaxhighlight lang="javascript">// Line breaks are in HTML
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>" );</langsyntaxhighlight>
 
 
Legitimate "one-liner" with grammar check, using declarative methods.
<langsyntaxhighlight lang="javascript">Array.from(Array(100).keys()).splice(1).reverse().forEach(n => console.log(`${n} bottle${n !== 1 ? 's' : ''} of beer on the wall\n${n} bottle${n !== 1 ? 's' : ''} of beer\nTake one down, pass it around\n${n - 1} bottle${n - 1 !== 1 ? 's' : ''} of beer on the wall\n\n`));</langsyntaxhighlight>
 
 
Object Oriented
<langsyntaxhighlight lang="javascript">function Bottles(count) {
this.count = count || 99;
}
Line 4,416 ⟶ 6,512:
 
var bar = new Bottles(99);
bar.sing();</langsyntaxhighlight>
 
An alternative version:
 
<langsyntaxhighlight lang="javascript">function bottleSong(n) {
if (!isFinite(Number(n)) || n == 0) n = 100;
var a = '%% bottles of beer',
Line 4,437 ⟶ 6,533:
}
 
window.onload = bottleSong;</langsyntaxhighlight>
 
=={{header|Joy}}==
<langsyntaxhighlight lang="joy">LIBRA
 
_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 == '". putch" putchars;
bottles == [dup small]
[ [null] [pop "no more bottles " putchars] [put "bottle " putchars] ifte]
[put "bottles " putchars] ifte ;
sing-verse == dup3 bottles beer wall comma
bottles beer ".\n" putchars
take1 1 -pred bottles beer wall period newline newline ;
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,465 ⟶ 6,561:
sing-verses == [null]
[sing-verse-0]
[sing-verse 1 -pred] tailrec .</lang>
END.
 
99 sing-verses.</syntaxhighlight>
 
=={{header|jq}}==
'''Minimalist:'''
<langsyntaxhighlight lang="jq">99
| (. - range(0;.+1) )
| "
Line 4,475 ⟶ 6,574:
\(.) bottles of beer
Take one down, pass it around
\(.) bottles of beer on the wall"</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="sh">$ jq -n -r -f 99_bottles.jq
...
 
Line 4,493 ⟶ 6,592:
0 bottles of beer
Take one down, pass it around
0 bottles of beer on the wall</langsyntaxhighlight>
'''Variant''':
<langsyntaxhighlight lang="jq">def sing:
def s: if . == 1 then "" else "s" end;
def bottles:
Line 4,509 ⟶ 6,608:
;
 
$bottles | tonumber | sing</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="sh">$ jq -r --arg bottles 99 -f 99_bottles_variant.jq
...
2 bottles of beer on the wall
Line 4,526 ⟶ 6,625:
No more bottles of beer
Take one down, pass it around
No more bottles of beer on the wall.</langsyntaxhighlight>
 
=={{header|Jsish}}==
<langsyntaxhighlight 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(); }
Line 4,540 ⟶ 6,639:
bottles--;
printf("%s bottle%s of beer on the wall\n\n", no(bottles), plural(bottles));
} while (bottles > 0);</langsyntaxhighlight>
 
=={{header|Julia}}==
'''one-liner'''
<langsyntaxhighlight lang="julia">for i = 99:-1:1 print("\n$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") end</langsyntaxhighlight>
another solution, handling grammar cases "No more bottles", "1 bottle", "<n> bottles"
<langsyntaxhighlight lang="julia">bottles(n) = n==0 ? "No more bottles" :
n==1 ? "1 bottle" :
"$n bottles"
Line 4,557 ⟶ 6,656:
$(bottles(n-1)) of beer on the wall
""")
end</langsyntaxhighlight>
shorter, but more cryptic, version of the previous `bottles` function
<langsyntaxhighlight lang="julia">bottles(n) = "$(n==0 ? "No more" : n) bottle$(n==1 ? "" : "s")"</langsyntaxhighlight>
 
=={{header|K}}==
<langsyntaxhighlight lang="k">`0:\:{x[z],y,a,x[z],a,"Take one down, pass it around",a,x[z-1],y,a,a:"\n"}[{($x)," bottle",:[x=1;"";"s"]," of beer"};" on the wall"]'|1_!100</langsyntaxhighlight>
 
=={{header|Kabap}}==
<syntaxhighlight lang="kabap">
<lang Kabap>
// Loop that spits lyrics to "99 Bottles of Beer"
 
Line 4,578 ⟶ 6,677:
 
return = $out;
</syntaxhighlight>
</lang>
 
=={{header|Kitten}}==
 
<langsyntaxhighlight lang="kitten">99 bottles_of_beer_on_the_wall
 
define bottles_of_beer_on_the_wall (Int32 -> +IO):
Line 4,613 ⟶ 6,712:
"one bottle"
else:
n show " bottles" cat</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="k">bottles::{:[x=1;"bottle";"bottles"]}
itone::{:[x=1;"it";"one"]}
numno::{:[x=0;"no";x]}
Line 4,634 ⟶ 6,758:
.d(bottles(x-1));
.p(" of beer on the wall");.p("")}
drink'1+|!99</langsyntaxhighlight>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">fun main(args: Array<String>) {
for (i in 99.downTo(1)) {
println("$i bottles of beer on the wall")
Line 4,644 ⟶ 6,768:
}
println("No more bottles of beer on the wall!")
}</langsyntaxhighlight>
 
=={{header|LabVIEW}}==
Line 4,652 ⟶ 6,776:
 
The signature file:
<langsyntaxhighlight Lambdalang="lambda Prologprolog">sig bottles.
 
type println string -> o.
type round int -> o.
type bottles_song int -> o.
</syntaxhighlight>
</lang>
 
The module file:
<langsyntaxhighlight Lambdalang="lambda Prologprolog">module bottles.
 
println Str :- print Str, print "\n".
Line 4,682 ⟶ 6,806:
M is N - 1,
bottles_song M.
</syntaxhighlight>
</lang>
 
Then we produce the desired output by setting the system to solve for this goal:
 
<syntaxhighlight lang="lambda Lambda Prologprolog">[bottles] ?- bottles_song 99.</langsyntaxhighlight>
 
=={{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,692 ⟶ 6,883:
=== Simple loop ===
 
<langsyntaxhighlight Lassolang="lasso">local(
beer = 99,
song = ''
Line 4,706 ⟶ 6,897:
}
 
#song</langsyntaxhighlight>
 
=== Query Expression ===
 
<langsyntaxhighlight Lassolang="lasso">(with beer in 99 to 1 by -1 select
#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')</langsyntaxhighlight>
 
 
=== Query Expression with Autocollect ===
 
<langsyntaxhighlight Lassolang="lasso">// this example adds an "s" to bottle until there is only 1 bottle left on the wall
 
local(s = 's')
Line 4,730 ⟶ 6,921:
'Take one down, pass it around,<br>'
#n + ' bottle' + #s + ' of beer on the wall.<br><br>'
^}</langsyntaxhighlight>
 
=={{header|LaTeX}}==
===Recursive===
<langsyntaxhighlight LaTeXlang="latex">\documentclass{articleminimal}
 
\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}</langsyntaxhighlight>
 
===Iterative===
Line 4,759 ⟶ 6,947:
Just for fun, this version uses Roman numerals.
 
<langsyntaxhighlight LaTeXlang="latex">\documentclass{articleminimal}
 
\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}</langsyntaxhighlight>
 
===References===
 
*Knuth, Donald E. (1984). ''The TeXbook'', Addison Wesley.
 
=={{header|lang5}}==
<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</lang>
 
=={{header|LDPL}}==
<langsyntaxhighlight lang="ldpl">
DATA:
bottles-in-the-wall is number
Line 4,828 ⟶ 7,001:
end if
repeat
</syntaxhighlight>
</lang>
 
=={{header|Lhogho}}==
<langsyntaxhighlight lang="logo">to bottle :i
if :i = 0 [output "|No more bottles of beer|]
if :i = 1 [output "|One bottle of beer|]
Line 4,863 ⟶ 7,036:
 
;Using it:
sing 99</langsyntaxhighlight>
 
=={{header|Limbo}}==
<syntaxhighlight lang="limbo">
<lang Limbo>
implement Beer;
 
Line 4,893 ⟶ 7,066:
 
}
</syntaxhighlight>
</lang>
 
=={{header|Lingo}}==
<langsyntaxhighlight Lingolang="lingo">repeat with i = 99 down to 2
put i & " bottles of beer on the wall"
put i & " bottles of beer"
Line 4,913 ⟶ 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"</langsyntaxhighlight>
 
=={{header|LiveCode}}==
<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</lang>
 
=={{header|Lisp}}==
Line 4,934 ⟶ 7,095:
 
=={{header|Logo}}==
<langsyntaxhighlight lang="logo">to bottles :n
if :n = 0 [output [No more bottles]]
if :n = 1 [output [1 bottle]]
Line 4,945 ⟶ 7,106:
print sentence bottles :n-1 [of beer on the wall]
end
for [n 99 1] [verse :n (print)]</langsyntaxhighlight>
 
=={{header|Logtalk}}==
<langsyntaxhighlight lang="logtalk">:- object(bottles).
 
:- initialization(sing(99)).
Line 4,970 ⟶ 7,131:
write(N), write(' bottles').
 
:- end_object.</langsyntaxhighlight>
 
=={{header|LOLCODE}}==
Line 4,976 ⟶ 7,137:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">local bottles = 99
 
local function plural (bottles) if bottles == 1 then return '' end return 's' end
Line 4,986 ⟶ 7,147:
print (bottles..' bottle'..plural(bottles)..' of beer on the wall')
print ()
end</langsyntaxhighlight>
 
With a numeric for-loop and string formatting:
 
<langsyntaxhighlight lang="lua">verse = [[%i bottle%s of beer on the wall
%i bottle%s of beer
Take one down, pass it around
Line 4,999 ⟶ 7,160:
for i = 99, 1, -1 do
print(verse:format(i, suffix(i), i, suffix(i), i-1, suffix(i-1)))
end</langsyntaxhighlight>
 
Using Lua relational operators and multiple return values:
 
<langsyntaxhighlight lang="lua">function bottles(i)
local s = i == 1 and "1 bottle of beer" or
i == 0 and "no more bottles of beer" or
Line 5,013 ⟶ 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</langsyntaxhighlight>
 
=={{header|Lucid}}==
<langsyntaxhighlight lang="lucid">// Run luval with -s inside the lucid shell script
// 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 5,028 ⟶ 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</langsyntaxhighlight>
 
=={{header|M4}}==
 
=={{header|NATURAL}}==
<lang m4>define(`BOTTLES', `bottles of beer')dnl
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 5,040 ⟶ 7,236:
ifelse(`$1',`0',,`TAKE')
ifelse(`$1',`0',,`NINETEEN(eval($1-1))')')dnl
NINETEEN(99)</langsyntaxhighlight>
 
=={{header|MACRO-11}}==
 
<syntaxhighlight lang="macro-11">
<lang MACRO-11>
;
; 99 BOTTLES OF BEER
Line 5,190 ⟶ 7,386:
 
 
.END START</langsyntaxhighlight>
 
=={{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 5,198 ⟶ 7,436:
{{libheader|jot}}
{{works with|BSD make}}
<langsyntaxhighlight lang="make">START = 99
UP != jot - 2 `expr $(START) - 1` 1
 
Line 5,224 ⟶ 7,462:
@echo $(START) bottles of beer on the wall,
@echo $(START) bottles of beer.
@echo Take one down, pass it around.</langsyntaxhighlight>
 
Usage: <tt>make</tt> or <tt>make START=99</tt>
Line 5,230 ⟶ 7,468:
=== GNU make ===
{{works with|GNU make|3.81}}
<langsyntaxhighlight lang="make">PRED=`expr $* - 1`
 
1-bottles: 1-beer pass
Line 5,246 ⟶ 7,484:
 
pass:
@echo "Take one down and pass it around,"</langsyntaxhighlight>
 
Usage: <tt>make 99-bottles</tt>
Line 5,255 ⟶ 7,493:
===== Without using a shell command to decrement the counter =====
{{works with|GNU make|3.81}}
<langsyntaxhighlight lang="make">digits:=9 8 7 6 5 4 3 2 1 0
numbers:=$(foreach x,$(filter-out 0,$(digits)),$(foreach y,$(digits),$x$y))
numbers+=$(digits)
Line 5,308 ⟶ 7,546:
@echo "$(most) $(bottles) $(beer) $(wall)!"
@echo ""
</syntaxhighlight>
</lang>
 
Usage: <tt>make</tt> or <tt>make N-bottles</tt> or <tt>make N</tt>
Line 5,317 ⟶ 7,555:
 
'''Long version''' (a real loop version made by Hisashi Iizawa)''':'''
<langsyntaxhighlight lang="malbolge">b'`;$9!=IlXFiVwwvtPO0)pon%IHGFDV|dd@Q=+^:('&Y$#m!1S|.QOO=v('98$65aCB}0i.Tw+QPU'7qK#I20jiDVgG
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,562 ⟶ 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</langsyntaxhighlight>
 
'''Short version''' (a just printing out the lyrics version made by Johannes E. Schindelin)''':'''
<langsyntaxhighlight lang="malbolge">DCBA@?>!}}{{yywwuussqqL-,+*)('&%$#c!a>v{z99wv5Ws3DpoA-lON*hg`_dc#a~_^Az>Z<;;uUN7
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,662 ⟶ 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</langsyntaxhighlight>
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">seq( printf( "%d %s of beer on the wall,\n%d %s of beer.\nTake one down, pass it around,\n%d %s of beer on the wall.\n\n",
i, `if`( i<>1, "bottles", "bottle" ),
i, `if`( i<>1, "bottles", "bottle" ),
i-1, `if`( i-1<>1, "bottles", "bottle") ),
i = 99..1, -1 );</langsyntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Bottle[n_] := ToString[n] <> If[n==1," bottle"," bottles"] <> " of beer"
 
BottleSong[n_] := Speak[
Line 5,681 ⟶ 7,919:
]
BottleSong /@ Range[99,1,-1]</langsyntaxhighlight>
 
=={{header|MATLAB}}==
<langsyntaxhighlight MATLABlang="matlab">function ninetyNineBottlesOfBeer()
 
disp( [ sprintf(['%d bottles of beer on the wall, %d bottles of beer.\n'...
Line 5,694 ⟶ 7,932:
%beer...like college.
end</langsyntaxhighlight>
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">bottles(n) := for i from n thru 1 step -1 do (
printf(true, "~d bottle~p of beer on the wall~%", i, i),
printf(true, "~d bottle~p of beer~%", i, i),
Line 5,722 ⟶ 7,960:
0 bottles of beer on the wall
 
*/</langsyntaxhighlight>
 
=={{header|MAXScript}}==
<langsyntaxhighlight lang="maxscript">escapeEnable = true
resetMaxFile #noPrompt
viewport.setType #view_top
Line 5,750 ⟶ 7,988:
redrawViews()
sleep delay
)</langsyntaxhighlight>
 
=== 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.
 
<langsyntaxhighlight lang="maxscript">for i = 99 to 1 by -1 do (print (i as string + (if i == 1 then " bottle" else " bottles") + " of beer on the wall\n" + i as string +\
(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 "")))</langsyntaxhighlight>
 
=={{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">
<lang Mercury>
% file: beer.m
% author:
Line 5,821 ⟶ 8,087:
string.format("%d bottles of beer", [i(N)])
).
</syntaxhighlight>
</lang>
 
=={{header|min}}==
{{works with|min|0.19.3}}
<langsyntaxhighlight lang="min">(swap quote interpolate puts!) :line
 
(
Line 5,836 ⟶ 8,102:
) :verse
 
99 'verse over times</langsyntaxhighlight>
 
=={{header|MiniScript}}==
Going for the simple/obvious solution here...
<langsyntaxhighlight MiniScriptlang="miniscript">bottles = function(n)
if n == 0 then return "no bottles"
if n == 1 then return "1 bottle"
Line 5,856 ⟶ 8,122:
for i in range(99, 1)
verse i
end for</langsyntaxhighlight>
{{out}}
<pre>99 bottles of beer on the wall
Line 5,881 ⟶ 8,147:
 
=={{header|MIPS Assembly}}==
<langsyntaxhighlight lang="mips">
##################################
# 99 bottles of beer on the wall #
Line 5,959 ⟶ 8,225:
li $v0,10
syscall
</syntaxhighlight>
</lang>
 
=={{header|Mirah}}==
<langsyntaxhighlight Mirahlang="mirah">plural = 's'
99.downto(1) do |i|
puts "#{i} bottle#{plural} of beer on the wall,"
Line 5,975 ⟶ 8,241:
end
end
</syntaxhighlight>
</lang>
 
=={{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}}==
<langsyntaxhighlight lang="mirc">var %x = 99
while (%x) {
echo -ag %x bottles of beer on the wall
Line 5,984 ⟶ 8,269:
dec %x
echo -ag %x bottles of beer on the wall
}</langsyntaxhighlight>
 
=={{header|mLite}}==
<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")</lang>
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|ML/I}}==
=== Simple iterative version ===
<langsyntaxhighlight MLlang="ml/Ii">MCSKIP "WITH" NL
"" 99 bottles - simple iterative version
MCSKIP MT,<>
Line 6,050 ⟶ 8,292:
>
"" Do it
BOTTLES 99</langsyntaxhighlight>
 
=== Recursive version ===
<langsyntaxhighlight MLlang="ml/Ii">MCSKIP "WITH" NL
"" 99 bottles - recursive version
MCSKIP MT,<>
Line 6,072 ⟶ 8,314:
>
"" Do it
BOTTLES 99</langsyntaxhighlight>
 
 
Line 6,095 ⟶ 8,337:
Internal macros define English word replacements for decimal numbers from 0 to 99.
 
<syntaxhighlight lang="ml/i">
<lang ML/I>
MCSKIP - WITH - NL
-- The line above defines the comment syntax: -- through to newline is completely deleted.
Line 6,194 ⟶ 8,436:
-- Sing 7 flasks of Armagnac on the table: Take a swig, throw it down!
-- Emilie vists, she brings some more.
</syntaxhighlight>
</lang>
 
=== Usage: ===
Line 6,201 ⟶ 8,443:
 
=== Output: ===
<syntaxhighlight lang="ml/i">
<lang ML/I>
Ninety nine bottles of beer on the wall,
Ninety nine bottles of beer.
Line 6,225 ⟶ 8,467:
Ninety nine bottles of beer on the wall!
 
</syntaxhighlight>
</lang>
 
=={{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}}==
<langsyntaxhighlight lang="modula2">MODULE b99;
IMPORT InOut;
 
Line 6,250 ⟶ 8,535:
InOut.WriteLn
UNTIL nr = 0
END b99.</langsyntaxhighlight>
 
=={{header|Modula-3}}==
<langsyntaxhighlight lang="modula3">MODULE Bottles EXPORTS Main;
 
IMPORT IO, Fmt;
Line 6,265 ⟶ 8,550:
IO.Put("\n");
END;
END Bottles.</langsyntaxhighlight>
 
=={{header|Monkey}}==
Tic's every one and a half seconds and sings(text's) the song out.
<Langsyntaxhighlight lang="monkey">
 
Import mojo
Line 6,346 ⟶ 8,631:
End
</syntaxhighlight>
 
 
</lang>
 
=={{header|MOO}}==
<lang moo>bottles = 99;
while (bottles > 0)
unit = (bottles == 1 ? "bottle" | "bottles");
player:tell(bottles, " ", unit, " of beer on the wall.");
player:tell(bottles, " ", unit, " of beer.");
player:tell("Take one down, pass it around.");
bottles = bottles - 1;
endwhile
player:tell("0 bottles of beer on the wall.");</lang>
 
=={{header|MoonScript}}==
<lang moonscript>p = (i) ->
i != 1 and 's' or ''
 
for b = 99,1,-1
for i = 1,4
print if i == 3
'Take one down, pass it around'
else
string.format '%s bottle%s of beer%s',
i < 4 and b or b-1,
i < 4 and (p b) or (p b-1),
i%3 == 1 and ' on the wall' or ''
io.write '\n'</lang>
 
=={{header|MUMPS}}==
===Recursive===
<lang MUMPS>beer(n) If n<1 Write "No bottles of beer on the wall... " Quit
Write !!,n," bottle",$Select(n=1:"",1:"s")," of beer on the wall."
Write !,n," bottle",$Select(n=1:"",1:"s")," of beer."
Write !,"Take one down, pass it around."
Do beer(n-1)
Quit
 
Do beer(99)</lang>
 
===Iterative===
<lang MUMPS>beer(n) If n<1 Write "No bottles of beer on the wall... " Quit
Write !!,n," bottle",$Select(n=1:"",1:"s")," of beer on the wall."
Write !,n," bottle",$Select(n=1:"",1:"s")," of beer."
Write !,"Take one down, pass it around."
Quit
 
For ii=99:-1:0 Do beer(ii)</lang>
 
===Brain-damaging===
<lang MUMPS>bottles
set template1="i_n_""of beer on the wall. ""_i_n_"" of beer. """
set template2="""Take""_n2_""down, pass it around. """
set template3="j_n3_""of beer on the wall."""
for i=99:-1:1 do write ! hang 1
. set:i>1 n=" bottles ",n2=" one " set:i=1 n=" bottle ",n2=" it "
. set n3=" bottle " set j=i-1 set:(j>1)!(j=0) n3=" bottles " set:j=0 j="No"
. write @template1,@template2,@template3
 
repeat
write "One more time!",! hang 5
goto bottles</lang>
 
=={{header|MontiLang}}==
<langsyntaxhighlight MontiLanglang="montilang">99 VAR i .
 
WHILE i
Line 6,419 ⟶ 8,642:
 
i 1 - VAR i .
ENDWHILE</langsyntaxhighlight>
 
Another way to solve the task that shows some more features of the language.
 
<langsyntaxhighlight MontiLanglang="montilang">&DEFINE botellas 99&
 
def rima
Line 6,439 ⟶ 8,662:
|No more| rima
 
|Press ENTER to end | INPUT clear</langsyntaxhighlight>
 
Infinite loop
 
<langsyntaxhighlight MontiLanglang="montilang">99 var botellas .
 
def rima /# n -- n #/
Line 6,466 ⟶ 8,689:
botellas out | bottles of beer on the wall.| print
|Press ENTER to continue | INPUT clear
endwhile</langsyntaxhighlight>
 
=={{header|MOO}}==
<syntaxhighlight lang="moo">bottles = 99;
while (bottles > 0)
unit = (bottles == 1 ? "bottle" | "bottles");
player:tell(bottles, " ", unit, " of beer on the wall.");
player:tell(bottles, " ", unit, " of beer.");
player:tell("Take one down, pass it around.");
bottles = bottles - 1;
endwhile
player:tell("0 bottles of beer on the wall.");</syntaxhighlight>
 
=={{header|MoonScript}}==
<syntaxhighlight lang="moonscript">p = (i) ->
i != 1 and 's' or ''
 
for b = 99,1,-1
for i = 1,4
print if i == 3
'Take one down, pass it around'
else
string.format '%s bottle%s of beer%s',
i < 4 and b or b-1,
i < 4 and (p b) or (p b-1),
i%3 == 1 and ' on the wall' or ''
io.write '\n'</syntaxhighlight>
 
=={{header|MUMPS}}==
===Recursive===
<syntaxhighlight lang="mumps">beer(n) If n<1 Write "No bottles of beer on the wall... " Quit
Write !!,n," bottle",$Select(n=1:"",1:"s")," of beer on the wall."
Write !,n," bottle",$Select(n=1:"",1:"s")," of beer."
Write !,"Take one down, pass it around."
Do beer(n-1)
Quit
 
Do beer(99)</syntaxhighlight>
 
===Iterative===
<syntaxhighlight lang="mumps">beer(n) If n<1 Write "No bottles of beer on the wall... " Quit
Write !!,n," bottle",$Select(n=1:"",1:"s")," of beer on the wall."
Write !,n," bottle",$Select(n=1:"",1:"s")," of beer."
Write !,"Take one down, pass it around."
Quit
 
For ii=99:-1:0 Do beer(ii)</syntaxhighlight>
 
===Brain-damaging===
<syntaxhighlight lang="mumps">bottles
set template1="i_n_""of beer on the wall. ""_i_n_"" of beer. """
set template2="""Take""_n2_""down, pass it around. """
set template3="j_n3_""of beer on the wall."""
for i=99:-1:1 do write ! hang 1
. set:i>1 n=" bottles ",n2=" one " set:i=1 n=" bottle ",n2=" it "
. set n3=" bottle " set j=i-1 set:(j>1)!(j=0) n3=" bottles " set:j=0 j="No"
. write @template1,@template2,@template3
 
repeat
write "One more time!",! hang 5
goto bottles</syntaxhighlight>
 
=={{header|MyDef}}==
Line 6,472 ⟶ 8,755:
<div>
mydef_page -mgeneral bottles.def
</div>
It outputs bottles.txt, which contains the lyrics.
 
<langsyntaxhighlight MyDeflang="mydef">bottles
$(for:i in 99-1)
$(i) bottles of beer on the wall
Line 6,483 ⟶ 8,766:
$(i) bottles of beer on the wall
NEWLINE
</syntaxhighlight>
</lang>
 
=={{header|N/t/roff}}==
Line 6,491 ⟶ 8,774:
 
{{works with|All TROFF}}
<langsyntaxhighlight Nlang="n/t/roff">.nr BS 99 1
.de L1
.ie \\n(BS>1 \{ \
Line 6,508 ⟶ 8,791:
.nf
.L1
.fi</langsyntaxhighlight>
 
===New version (compatible only with GNU TROFF)===
Line 6,514 ⟶ 8,797:
 
{{works with|GNU TROFF|1.22.2}}
<langsyntaxhighlight Nlang="n/t/roff">.nr beers 99 1
.nf
.while \n[beers]>0 \{ \
Line 6,528 ⟶ 8,811:
\n-[beers] bottles of beer on the wall.
\} \" while \n[beers]>0
.fi</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
{{trans|Ursa}}
<langsyntaxhighlight lang="nanoquery">//
// 99 bottles of beer
//
Line 6,554 ⟶ 8,837:
println "1 bottle of beer on the wall.\n"
end if
end for</langsyntaxhighlight>
 
=={{header|NASL}}==
<langsyntaxhighlight lang="nasl">bottles = 99;
repeat {
display(bottles, ' bottles of beer on the wall\n');
Line 6,563 ⟶ 8,846:
display('Take one down, pass it around\n');
display(--bottles, ' bottles of beer on the wall\n\n');
} until bottles < 1;</langsyntaxhighlight>
 
 
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
<lang ActionScript>/**
<doc>
<h3>Rosetta Code, 99 bottles of beer on the wall, in Neko</h3>
Line 6,597 ⟶ 8,879:
$print(nonesome(beers), plural(beers), message);
if (beers > 0) $print("\n");
}</langsyntaxhighlight>
 
{{out}}
Line 6,614 ⟶ 8,896:
 
=={{header|Nemerle}}==
<langsyntaxhighlight Nemerlelang="nemerle">using System;
using System.Console;
 
Line 6,637 ⟶ 8,919:
Sing(i)
}
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight lang="netrexx">
beer = "bottles of beer on the wall"
removeOne = "Take one down, pass it arround,"
Line 6,660 ⟶ 8,942:
say removeOne
say "No more" beer
</syntaxhighlight>
</lang>
 
=={{header|NewLISPnewLISP}}==
See [[99 Bottles of Beer/Lisp]]
 
=={{header|Nial}}==
<langsyntaxhighlight lang="nial">line is fork [
0=, 'No more bottles of beer' first,
1=, 'One bottle of beer' first,
Line 6,678 ⟶ 8,960:
]
 
bottles is iterate (write verse) reverse count</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="nim">proc GetBottleNumbergetBottleNumber(n: int): string =
case n
var bs: string
if n ==of 0:
bsresult = "No more bottles"
elif n ==of 1:
bsresult = "1 bottle"
else:
bsresult = $n & " bottles"
return bsresult &= " of beer"
 
for bn in countdown(99, 1):
varlet cur = GetBottleNumbergetBottleNumber(bn)
echo(cur, " on the wall, ", cur, ".")
echo("Take one down and pass it around, ", GetBottleNumbergetBottleNumber(bn-1), " on the wall.\n")
 
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."</langsyntaxhighlight>
 
other:
 
<langsyntaxhighlight lang="nim">from strutils import format
for i in countdown(99, 1):
Line 6,721 ⟶ 9,025:
No more bottles of beer on the wall""", i)
else:
discard</langsyntaxhighlight>
 
compact:
 
<langsyntaxhighlight lang="nim">from strutils import format
 
proc pluralize(a: int): string =
if a > 1 or a == 0: return "s"
else: return ""
 
for i in countdown(99, 1):
Line 6,735 ⟶ 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))</langsyntaxhighlight>
 
organized:
 
<langsyntaxhighlight lang="nim">from strutils import format
 
var verse = """$1 bottle$3 of beer on the wall
Line 6,747 ⟶ 9,051:
 
proc pluralize(a: int): string =
if a > 1 or a == 0: return "s"
else: return ""
 
for i in countdown(99, 1):
echo format(verse, i, i-1, pluralize(i), pluralize(i-1))</langsyntaxhighlight>
 
=={{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"
<langsyntaxhighlight NSlang="ns-HUBASIChubasic">10 WALL$=" ON THE WALL"
20 FOR BOTTLES=99 TO 1 STEP -1
30 BOTTLES$=" BOTTLES OF BEER"
Line 6,765 ⟶ 9,083:
90 IF BOTTLES-1=0 THEN BOTTLE$=" BOTTLES OF BEER"
100 PRINT BOTTLES-1 BOTTLES$ WALL$
110 NEXT</langsyntaxhighlight>
 
Without grammatical support for "1 bottle of beer"
<langsyntaxhighlight NSlang="ns-HUBASIChubasic">10 BOTTLES$=" BOTTLES OF BEER"
20 WALL$=" ON THE WALL"
30 FOR BOTTLES=99 TO 1 STEP -1
Line 6,775 ⟶ 9,093:
60 PRINT "TAKE ONE DOWN, PASS IT AROUND"
70 PRINT BOTTLES-1 BOTTLES$ WALL$
80 NEXT</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="oasys_oac">
class player {}
 
Line 6,809 ⟶ 9,139:
print "Type 'beer' for beer.\nType 'quit' to quit.\n"
}
</syntaxhighlight>
</lang>
 
=={{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}}==
<langsyntaxhighlight lang="objeck">
class Bottles {
function : Main(args : String[]) ~ Nil {
Line 6,827 ⟶ 9,183:
} while(bottles > 0);
}
}</langsyntaxhighlight>
 
=={{header|Objective-C}}==
<langsyntaxhighlight lang="objc">#import <Foundation/Foundation.h>
 
int main()
Line 6,846 ⟶ 9,202:
}
return 0;
}</langsyntaxhighlight>
 
=={{header|Oberon-2}}==
<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.</lang>
 
=={{header|OCaml}}==
===For-loop===
<langsyntaxhighlight lang="ocaml">for n = 99 downto 1 do
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</langsyntaxhighlight>
 
===Recursive===
Recursive version that handles plurals.
 
<langsyntaxhighlight lang="ocaml">let verse n =
let
line2 = function
Line 6,910 ⟶ 9,240:
if n > 1 then beer (n-1);;
 
beer 99;;</langsyntaxhighlight>
 
===Monadic===
Monadic version, expressing actions which evolve the program state and log output. Special cases and grammar rules are handled.
 
<langsyntaxhighlight lang="ocaml">(* A basic "Writer" monoid with emit *)
module Writer = struct
type 'a t = 'a * string
Line 6,940 ⟶ 9,270:
| n -> take n >>= summary |> verse)
let sing start =
Writer.(emit (verse (return start)))</langsyntaxhighlight>
 
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,954 ⟶ 9,284:
Go to the store and buy some more, 99 bottles of beer on the wall.
 
- : int = 99</langsyntaxhighlight>
 
Note the output value is 99... reflecting the state at termination.
 
=={{header|Octave}}==
<langsyntaxhighlight lang="octave">function bottles(n)
bottle = "bottle";
ofbeer = "of beer";
Line 6,981 ⟶ 9,311:
endfunction
 
bottles(99);</langsyntaxhighlight>
=={{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}}==
 
<langsyntaxhighlight Oforthlang="oforth">"bottles of beer on the wall\n" const: B
"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 </langsyntaxhighlight>
 
=={{header|Ol}}==
Line 6,995 ⟶ 9,354:
=={{header|Onyx}}==
 
<langsyntaxhighlight Onyxlang="onyx">$Bottles {
dup cvs ` bottle' cat exch 1 ne {`s' cat} if
` of beer' cat
Line 7,010 ⟶ 9,369:
} def
 
99 -1 1 {WriteStanza} for</langsyntaxhighlight>
 
Output:
Line 7,028 ⟶ 9,387:
 
=={{header|OOC}}==
<langsyntaxhighlight lang="ooc">
sing_line: func (b: Int, suffix: Bool) {
"#{b > 0 ? "#{b}" : "No more"} bottle#{b == 1 ? "" : "s"}" print()
Line 7,053 ⟶ 9,412:
}
}
</syntaxhighlight>
</lang>
 
=={{header|ooRexx}}==
Line 7,059 ⟶ 9,418:
 
=={{header|OpenEdge/Progress}}==
<langsyntaxhighlight Progresslang="progress (Openedgeopenedge ABLabl)">DEFINE VARIABLE amountofbottles AS INTEGER NO-UNDO INITIAL 99.
&GLOBAL-DEFINE bbm bottles of beer
&GLOBAL-DEFINE bbs bottle of beer
Line 7,091 ⟶ 9,450:
END.
RETURN 0.
END FUNCTION.</langsyntaxhighlight>
 
=={{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 7,098 ⟶ 9,479:
==="Pure" Order===
This solution uses only Order language constructs to generate and manipulate tokens:
<langsyntaxhighlight lang="c">#include "order/interpreter.h"
 
ORDER_PP
Line 7,114 ⟶ 9,495:
(take one down, pass it around,) 8space
8ap(8B, 8dec(8N)) (of beer on the wall.))),
100, 1)))</langsyntaxhighlight>
 
===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:
<langsyntaxhighlight lang="c">#include "order/interpreter.h"
 
#define GEN_phrase(N_bottles, N_minus_1_bottles) \
Line 7,141 ⟶ 9,522:
100, 1))
 
#undef GEN_phrase</langsyntaxhighlight>
 
Either example could obviously also form the core of a C solution (demonstrating the intended use of Order).
 
=={{header|Oxygene}}==
<langsyntaxhighlight lang="oxygene">
namespace ConsoleApplication2;
 
Line 7,181 ⟶ 9,562:
 
end.
</syntaxhighlight>
</lang>
 
 
=={{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.
<langsyntaxhighlight lang="oz">declare
%% describe the possible solutions of the beer 'puzzle'
proc {BeerDescription Solution}
Line 7,211 ⟶ 9,591:
%% show all solutions to the 'puzzle'
{ForAll {SearchAll BeerDescription}
System.showInfo}</langsyntaxhighlight>
 
=== Iterative ===
<langsyntaxhighlight lang="oz">declare
fun {Bottles N}
if N == 1 then "1 bottle"
Line 7,227 ⟶ 9,607:
"Take one down, pass it around\n"#
{Bottles I-1}#" of beer on the wall\n"}
end</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">forstep(n=99,3,-1,
print(n" bottles of beer on the wall");
print(n" bottles of beer");
Line 7,237 ⟶ 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")</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl -w
 
my $verse = <<"VERSE";
Line 7,260 ⟶ 9,653:
print $verse;
redo unless $done;
}</langsyntaxhighlight>
 
Alternatively:
<langsyntaxhighlight lang="perl">for $n (reverse(0..99))
{
$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")) );
}</langsyntaxhighlight>
 
Correct grammar and nice spacing in modern perl:
<langsyntaxhighlight lang="perl">use 5.10.0;
 
$num = 99;
Line 7,284 ⟶ 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.";</langsyntaxhighlight>
 
Using perl5 as a DSL factory leveraging $_'s global nature:
<langsyntaxhighlight lang="perl">
#!/usr/bin/env perl
use strict;
Line 7,303 ⟶ 9,696:
, take
, bottles, qq{\n\n}
} for reverse 0..99;</langsyntaxhighlight>
 
=={{header|Perl 6}}==
 
=== A Simple Way ===
 
<lang perl6>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";
}</lang>
 
=== 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.
 
<lang perl6>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"
}</lang>
 
=== A More Extravagant Way ===
 
{{works with|Rakudo|2015.09}}
<lang perl6>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";
}</lang>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang phix>constant ninetynine = 99 -- (set this to 9 for testing)
<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>
 
function bottles(integer count)
<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>
if count=0 then return "no more bottles "
<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>
elsif count=1 then return "1 bottle " end if
<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>
if count=-1 then count = ninetynine end if
<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>
return sprintf("%d bottles ",count)
<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>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
 
function bob(integer count)
<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>
return bottles(count)&"of beer"
<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>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
 
function up1(string bob)
<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>
-- Capitalise sentence start (needed just the once, "no more"=>"No more")
<span style="color: #000080;font-style:italic;">-- Capitalise sentence start (needed just the once, "no more"=&gt;"No more")</span>
bob[1] = upper(bob[1])
<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>
return bob
<span style="color: #008080;">return</span> <span style="color: #000000;">bob</span>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
 
string this = bob(ninetynine)
<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>
string that = "Take one down, pass it around,\n"
<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>
for i=ninetynine to 0 by -1 do
<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>
puts(1,up1(this)&" on the wall,\n")
<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>
puts(1,this&".\n")
<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>
if i=0 then that = "Go to the store, buy some more,\n"
<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>
elsif i=1 then that[6..8] = "it" end if
<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>
this = bob(i-1)
<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>
puts(1,that&this&" on the wall.\n\n")
<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>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
{} = wait_key()</lang>
<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}}==
<langsyntaxhighlight Phixmontilang="phixmonti">def bottles
dup if
dup 1 == if
Line 7,416 ⟶ 9,753:
 
99 1 -1 3 tolist
for verse . endfor</langsyntaxhighlight>
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 down, pass it around," ?
1 - bottles print " on the wall." ? nl
drop
endfor</syntaxhighlight>
 
=={{header|PHL}}==
Line 7,422 ⟶ 9,781:
{{trans|C}}
 
<langsyntaxhighlight lang="phl">module bottles;
extern printf;
 
Line 7,436 ⟶ 9,795:
} while(bottles > 0);
return 0;
]</langsyntaxhighlight>
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php"><?php
$plural = 's';
foreach (range(99, 1) as $i) {
Line 7,453 ⟶ 9,812:
echo "No more bottles of beer on the wall!\n";
}
?></langsyntaxhighlight>
 
===shorter way===
<langsyntaxhighlight lang="php"><?php
foreach(range(99,1) as $i) {
$p = ($i>1)?"s":"";
Line 7,468 ⟶ 9,827:
}
echo "No more Bottles of beer on the wall";
?></langsyntaxhighlight>
 
 
===modifing way:===
===Tag syntax===
<lang php><?php
<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===
<syntaxhighlight lang="php"><?php
$verse = <<<VERSE
100 bottles of beer on the wall,
Line 7,488 ⟶ 9,860:
echo $verse;
}
?></langsyntaxhighlight>
 
===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
<langsyntaxhighlight lang="php"><?php
for($i=100;$i>0;$i--){
$p2=$i." bottle".(($i>1)?"s":"")." of beer";
Line 7,499 ⟶ 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):"");
}</langsyntaxhighlight>
 
===gettext alternative===
supports grammar and translations.
 
<langsyntaxhighlight lang="php"><?php
 
$bottles = 99;
Line 7,519 ⟶ 9,891:
}
}
printf('No more bottles of beer on the wall'); //No more bottles of beer on the wall</langsyntaxhighlight>
 
===Using printf===
Fun with HEREDOC and printf placeholders
 
<langsyntaxhighlight lang="php"><?php
 
$lyrics = <<<ENDVERSE
Line 7,539 ⟶ 9,911:
printf( $lyrics, $x != 1 ? 's' : '', $x--, $x != 1 ? 's' : '', $x > 0 ? $x : 'No more' );
}
</syntaxhighlight>
</lang>
{{Out}}
 
Line 7,592 ⟶ 9,964:
 
=={{header|Picat}}==
<syntaxhighlight lang="picat">
<lang Picat>
beer1(N) =>
Beer = N,
Line 7,618 ⟶ 9,990:
cond(B > 0, (B-1).to_string() ++ BT ++ BW ++ NL, ""),
S = S1.
</syntaxhighlight>
</lang>
 
=={{header|PicoLisp}}==
See [[99 Bottles of Beer/Lisp]]
 
=={{header|Piet}}==
Line 7,624 ⟶ 9,999:
 
=={{header|Pike}}==
<langsyntaxhighlight lang="pike">int main(){
for(int i = 99; i > 0; i--){
write(i + " bottles of beer on the wall, " + i + " bottles of beer.\n");
Line 7,631 ⟶ 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");
}</langsyntaxhighlight>
 
alternate version:
<langsyntaxhighlight Pikelang="pike">// disclaimer: i prefer gingerale
 
void main()
Line 7,657 ⟶ 10,032:
string song = bottles * "take one down, pass it around,\n";
write(song);
}</langsyntaxhighlight>
 
=={{header|PIRPILOT}}==
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}}
 
<langsyntaxhighlight lang="pir">.sub sounding_smart_is_hard_after_drinking_this_many
.param int b
if b == 1 goto ONE
Line 7,693 ⟶ 10,088:
DRUNK:
end
.end</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="tex">\def\ifbeer{\ifnum\number\bottles}
\def\beers{
\par\ifbeer>0 \the\bottles~\else No more \fi
Line 7,718 ⟶ 10,143:
\ifnum\number\bottles>0\repeat
 
\bye</langsyntaxhighlight>
 
=={{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 ===
<langsyntaxhighlight lang="pony">actor Main
let _env: Env
new create(env: Env) =>
Line 7,741 ⟶ 10,309:
end
bottles(n-1)
end</langsyntaxhighlight>
=== Iterative ===
<langsyntaxhighlight lang="pony">actor Main
let _env: Env
new create(env: Env) =>
Line 7,760 ⟶ 10,328:
end
n = n - 1
until n < 0 end</langsyntaxhighlight>
 
=={{header|Pop11}}==
<langsyntaxhighlight lang="pop11">define bootles(n);
while n > 0 do
printf(n, '%p bottles of beer on the wall\n');
Line 7,773 ⟶ 10,341:
enddefine;
 
bootles(99);</langsyntaxhighlight>
 
=={{header|PostScript}}==
<syntaxhighlight lang="postscript">%!PS
<lang PostScript>%!PS
/Helvetica findfont 9 scalefont setfont
 
Line 7,812 ⟶ 10,380:
song
showpage
%%EOF</langsyntaxhighlight>
 
=={{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,818 ⟶ 10,402:
 
=={{header|Processing}}==
==='''Console output==='''
 
Immediately prints all output to the console.
<langsyntaxhighlight Processinglang="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");
}</langsyntaxhighlight>
 
'''Visual and animated'''
 
===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.
<langsyntaxhighlight Processinglang="java">int i = 99;
void setup() {
size(200, 140);
Line 7,835 ⟶ 10,421:
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
Line 7,846 ⟶ 10,432:
i = max(i-1, 1); // stop decreasing at 1-0 bottles
}
</syntaxhighlight>
</lang>
 
==={{header|ProDOSProcessing Python mode}}===
{{trans|Processing}}
See [[99 Bottles of Beer/Shell]]
<syntaxhighlight lang="python">i = 99
def setup():
size(200, 140)
 
def draw():
=={{header|Prolog}}==
background(0)
See [[99 Bottles of Beer/Prolog]]
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():
=={{header|Python}}==
global i
===Simplest version (currently)===
i = max(i - 1, 1) # stop decreasing at 1-0 bottles</syntaxhighlight>
{{Works with|Python|2.6+}}
Inspired by [http://www.99-bottles-of-beer.net/language-python-573.html 99-bottles-of-beer.net]
<lang Python>catchphrase = "%d bottles of beer on the wall"
 
==={{header|Processing.R}}===
strofas = ("\n".join((
'''Console output'''
catchphrase % n,
catchphrase[:18] % n,
"Take one down and pass it around",
catchphrase % (n-1)
)) for n in range(99, 0, -1))
 
<syntaxhighlight lang="r">setup <- function() {
print("\n\n".join(strofas))
stdout$print(bottlesong(99))
</lang>
}
 
bottlesong <- function(num) {
===Python 3===
verses = ""
{{Works with|Python|3.7}}
for(i in num:1){
<lang Python>#!/usr/bin/env python3
verses = paste0(verses,
# -*- coding: utf-8 -*-
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}}==
"""Pythonic 99 beer song (maybe the simplest naive implementation in Python 3)."""
See [[99 Bottles of Beer/Shell]]
 
=={{header|Prolog}}==
See [[99 Bottles of Beer/Prolog]]
 
=={{header|Python}}==
REGULAR_VERSE = '''\
===One line===
{n} bottles of beer on the wall, {n} bottles of beer
{{Works with|Python|3.6+}}
Take one down and pass it around, {n_minus_1} bottles of beer on the wall.
 
Short, one-line version.
'''
 
<syntaxhighlight lang="python">
ENDING_VERSES = '''\
2for i in range(99, 0, -1):b='bottles of beer';w=f' {b} on the wall';print(f'{i}{w}, 2{i} bottles{b}\nTake ofone beerdown and pass it around, {i-1}{w}.\n')
</syntaxhighlight>
Take one down and pass it around, 1 bottle of beer on the wall.
 
===Pythonic version===
1 bottle of beer on the wall, 1 bottle of beer.
{{Works with|Python|3}}
Take one down and pass it around, no more bottles of beer on the wall.
 
<syntaxhighlight lang="python">
No more bottles of beer on the wall, no more bottles of beer.
VERSE = '''\
Go to the store and buy some more, 99 bottles of beer on the wall.
{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, 20, -1):
if n == 1:
print(REGULAR_VERSE.format(n=n, n_minus_1=n - 1))
n_minus_1 = 'No more'
print(ENDING_VERSES)
s = ''
</lang>
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>
 
===Functional===
{{Trans|Haskell}}
{{Works with|Python|3.7+}}
<langsyntaxhighlight lang="python">'''99 Units of Disposable Asset'''
 
 
Line 8,015 ⟶ 10,637:
 
if __name__ == '__main__':
main()</langsyntaxhighlight>
 
===Functional, pythonic version===
Line 8,023 ⟶ 10,645:
Inspired by [[99_Bottles_of_Beer#Functional|Functional version]]
 
<langsyntaxhighlight lang="python">"""
99 Bottles of Beer on the Wall made functional
Line 8,151 ⟶ 10,773:
if __name__ == '__main__':
print(beer_song())
</syntaxhighlight>
</lang>
 
{{Out}}
Line 8,183 ⟶ 10,805:
Inspired by the [[99_Bottles_of_Beer#Python_3.2C_functional.2C_pythonic_version|Functional Pythonic Version]]
 
<langsyntaxhighlight lang="python">"""
Excercise of style. An overkill for the task :-D
 
Line 8,439 ⟶ 11,061:
 
__all__ = (Song.__name__, MuchItemsSomewhere.__name__, muchBeersOnTheWall.__name__, balladOfProgrammer.__name__)
</syntaxhighlight>
</lang>
 
=== Other solutions ===
Line 8,445 ⟶ 11,067:
 
=={{header|Q}}==
<langsyntaxhighlight lang="q">bobw:{[n] {x," bottles of beer on the wall\n",x," bottles of beer\nTake one down, pass it around\n",y," bottles of beer on the wall\n\n"} . string (n;n-1)}
-1 bobw each reverse 1 + til 99</langsyntaxhighlight>
 
=={{header|QB64}}==
Line 8,452 ⟶ 11,074:
'''[NOTE]:''' The code below is an amazing, full-on media event! For a simpler version, click [[99_Bottles_of_Beer/Basic#QB64 | HERE.]]
----
<langsyntaxhighlight QB64lang="qb64">SCREEN _NEWIMAGE(800, 600, 32)
CONST BottleSpeed = 3
PLAY "<"
Line 8,563 ⟶ 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>
</lang>
 
=={{header|Qore}}==
Line 8,569 ⟶ 11,191:
===Simple Solution===
 
<langsyntaxhighlight lang="qore">#!/usr/bin/env qore
 
%enable-all-warnings
Line 8,578 ⟶ 11,200:
printf("take one down, pass it around\n");
printf("%d bottles of beer on the wall\n", $i);
}</langsyntaxhighlight>
 
===Concurrent (Unordered) Solution===
 
<langsyntaxhighlight lang="qore">#!/usr/bin/env qore
%enable-all-warnings
Line 8,609 ⟶ 11,231:
}
 
$count.waitForZero();</langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight lang="quill">bottles := void(int count) {
(count > 0) if {
new_count := count - 1;
Line 8,626 ⟶ 11,286:
}
};
99 bottles</langsyntaxhighlight>
 
=={{header|Quite BASIC}}==
With grammatical support for "1 bottle of beer"
<langsyntaxhighlight Quitelang="quite BASICbasic">10 let w=" on the wall"
20 for n=99 to 1 step -1
30 let b=" bottles of beer"
Line 8,640 ⟶ 11,300:
90 if n-1=0 then let b=" bottles of beer"
100 print n-1;b;w
110 next n</langsyntaxhighlight>
 
Without grammatical support for "1 bottle of beer"
<langsyntaxhighlight Quitelang="quite BASICbasic">10 let b=" bottles of beer"
20 let w=" on the wall"
30 for n=99 to 1 step -1
Line 8,650 ⟶ 11,310:
60 print "Take one down, pass it around"
70 print n-1;b;w
80 next n</langsyntaxhighlight>
 
=={{header|R}}==
===Simple looping solution===
 
<langsyntaxhighlight lang="rsplus">#a naive function to sing for N bottles of beer...
 
song = function(bottles){
Line 8,670 ⟶ 11,330:
}
 
song(99)#play the song by calling the function</langsyntaxhighlight>
 
===Vector solutions===
<langsyntaxhighlight lang="rsplus">#only one line!
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'))</lang>
 
#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">
<lang Ra>
class BottlesOfBeer
**Prints the "99 Bottles of Beer" song"**
Line 8,730 ⟶ 11,393:
if bottle = 1, return "1 bottle"
return "[bottle] bottles"
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket
(define (sing bottles)
Line 8,742 ⟶ 11,405:
(unless (= 1 bottles) (sing (sub1 bottles))))
(sing 99)
</syntaxhighlight>
</lang>
 
=={{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">
<lang RapidQ>
dim nBott as integer
nBott = 99
Line 8,759 ⟶ 11,481:
while inkey$="":wend
end
</syntaxhighlight>
</lang>
 
=={{header|Rascal}}==
<langsyntaxhighlight lang="rascal">
module demo::basic::Bottles
 
Line 8,779 ⟶ 11,501:
println("Go to the store and buy some more, 99 bottles of beer on the wall.");
}
</syntaxhighlight>
</lang>
 
=={{header|Raven}}==
<langsyntaxhighlight lang="raven">99 0 1 range each as $i
$i 1 = if
"bottle" as $b
Line 8,794 ⟶ 11,516:
else
$i 1 - "%d bottles" format
"%s of beer on the wall.\n\n" print</langsyntaxhighlight>
{{out}}
Last couple of stanzas are:
Line 8,813 ⟶ 11,535:
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">rebol [
Title: "99 Bottles of Beer"
URL: http://rosettacode.org/wiki/99_Bottles_of_Beer
Line 8,831 ⟶ 11,553:
"Take one down, pass it around" crlf
bottles n - 1 "of beer on the wall" crlf
]]</langsyntaxhighlight>
 
Output ''(selected highlights)'':
Line 8,850 ⟶ 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:
 
<langsyntaxhighlight REBOLlang="rebol">for i 99 1 -1 [
x: rejoin [
i b: " bottles of beer" o: " on the wall. " i b
Line 8,858 ⟶ 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</langsyntaxhighlight>
Here's a simple 1 line console version:
<langsyntaxhighlight REBOLlang="rebol">for i 99 1 -1[print rejoin[i b:" bottles of beer"o:" on the wall. "i b". Take one down, pass it around. "(i - 1)b o"^/"]]</langsyntaxhighlight>
 
=={{header|Red}}==
<langsyntaxhighlight Redlang="red">Red [
Title: "99 Bottles of Beer"
Original-Author: oofoe
Line 8,885 ⟶ 11,607:
"Take one down, pass it around" crlf
bottles n - 1 "of beer on the wall" crlf
]]</langsyntaxhighlight>
 
=={{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.
 
<langsyntaxhighlight Retrolang="retro"># 99 Bottles
 
Display the text for the *99 Bottles of Beer* song.
Line 8,917 ⟶ 11,696:
#99 verses
~~~</langsyntaxhighlight>
 
=={{header|REXX}}==
Complete with a PSA &nbsp; (<u>P</u>ublic <u>S</u>ervice <u>A</u>nnouncement) &nbsp; comment.
<langsyntaxhighlight lang="rexx">/*REXX program displays lyrics to the infamous song "99 Bottles of Beer on the Wall". */
parse arg N .; if N=='' | N=="," then N=99 /*allow number of bottles be specified.*/
/* [↓] downward count of beer bottles.*/
Line 8,940 ⟶ 11,719:
exit /*we're all done, and also sloshed !. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
s: if arg(1)=1 then return ''; return 's' /*simple pluralizer for gooder English.*/</langsyntaxhighlight>
{{out|output|text=&nbsp; &nbsp; Below is the first and last three verses of the song:}}
<pre>
Line 8,980 ⟶ 11,759:
=={{header|Ring}}==
This is a simple solution
<langsyntaxhighlight lang="ring">for i = 99 to 0 step -1
switch i
on 0
Line 9,001 ⟶ 11,780:
"
off
next</langsyntaxhighlight>
{{out}}
<pre>
Line 9,027 ⟶ 11,806:
Rockstar solution without special cases for the last 2 verses.
 
<langsyntaxhighlight lang="rockstar">Love is " bottles of beer on the wall"
Problems are " bottles of beer"
Carol says Take one down, pass it around
Line 9,037 ⟶ 11,816:
Knock the beers down
Say it with Love
</syntaxhighlight>
</lang>
 
=={{header|RPG}}==
Line 9,043 ⟶ 11,822:
{{works with|RPGIII|}}
 
<langsyntaxhighlight RPGlang="rpg"> H/TITLE 99 Bottles of Beer on the Wall - RPGIII (IBM System/38)
F********************************************************************
F*
Line 9,133 ⟶ 11,912:
O 15 'Pass it around'
O E 1 SKIPLN
</syntaxhighlight>
</lang>
 
=={{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===
<langsyntaxhighlight lang="rpl/2">BEER
<<
99 do
Line 9,158 ⟶ 11,952:
<<
" bottle" + over if 1 <> then "s" + end " of beer" +
>></langsyntaxhighlight>
 
===Recursive and multithreaded solution===
<langsyntaxhighlight lang="rpl/2">BOTTLES
<<
// Child process is started.
Line 9,203 ⟶ 11,997:
RECURSIVE
end
>></langsyntaxhighlight>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">plural = 's'
99.downto(1) do |i|
puts "#{i} bottle#{plural} of beer on the wall,"
Line 9,218 ⟶ 12,012:
puts "No more bottles of beer on the wall!"
end
end</langsyntaxhighlight>
 
Ruby has variable traces, so we can do
<langsyntaxhighlight lang="ruby">trace_var :$bottle_num do |val|
$bottles = %Q{#{val == 0 ? 'No more' : val.to_s} bottle#{val == 1 ? '' : 's'}}
end
Line 9,232 ⟶ 12,026:
puts "#{$bottles} of beer on the wall"
puts ""
end</langsyntaxhighlight>
or...
<langsyntaxhighlight lang="ruby">def bottles(of_beer, ending)
puts "#{of_beer} bottle#{ending} of beer on the wall,"
puts "#{of_beer} bottle#{ending} of beer"
Line 9,248 ⟶ 12,042:
puts "No more bottles of beer on the wall!"
end
end</langsyntaxhighlight>
or...
<langsyntaxhighlight lang="ruby">def bottles(beer, wall = false)
"#{beer>0 ? beer : "no more"} bottle#{"s" if beer!=1} of beer#{" on the wall" if wall}"
end
Line 9,263 ⟶ 12,057:
end
puts ", #{bottles(remaining-1,true)}.\n\n"
end</langsyntaxhighlight>
 
===Simple solution===
<langsyntaxhighlight lang="ruby">
99.downto(1) do |bottles|
puts "#{bottles} bottle#{"s" if bottles != 1} of beer on the wall.",
Line 9,273 ⟶ 12,067:
"#{bottles - 1} bottle#{"s" if bottles - 1 != 1} of beer on the wall.\n\n"
end
</syntaxhighlight>
</lang>
 
=={{header|Rust}}==
 
===Simple Solution===
<langsyntaxhighlight lang="rust">fn main() {
for n in (0..100).rev() {
match n {
Line 9,295 ⟶ 12,089:
}
}
}</langsyntaxhighlight>
 
===Using a trait and impl===
<langsyntaxhighlight lang="rust">trait Bottles {
fn bottles_of_beer(&self) -> Self;
fn on_the_wall(&self);
Line 9,326 ⟶ 12,120:
println!("-----------------------------------");
}
}</langsyntaxhighlight>
 
=={{header|Sather}}==
<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;</lang>
 
=={{header|S-BASIC}}==
<langsyntaxhighlight lang="basic">
rem - print lyrics to "99 Bottles of Beer on the Wall"
 
Line 9,389 ⟶ 12,167:
 
end
</syntaxhighlight>
</lang>
 
=={{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}}==
{{works with|Chicken Scheme}}
<lang scheme>(define (bottles x)
(format #t "~a bottles of beer on the wall~%" x)
(format #t "~a bottles of beer~%" x)
(format #t "Take one down, pass it around~%")
(format #t "~a bottles of beer on the wall~%" (- x 1))
(if (> (- x 1) 0)
(bottles (- x 1))))</lang>
 
=={{header|Scheme}}==
 
<langsyntaxhighlight lang="scheme">
(define (sing)
(define (sing-to-x n)
Line 9,420 ⟶ 12,203:
(display "would you wanna me to sing it again?")))
(sing-to-x 99))
</syntaxhighlight>
</lang>
 
=={{header|Scratch}}==
Line 9,426 ⟶ 12,209:
 
=={{header|sed}}==
<langsyntaxhighlight lang="sed">s/.*/99 bottles of beer on the wall/
h
: b
Line 9,451 ⟶ 12,234:
y/0123456789/9012345678/
h
bb</langsyntaxhighlight>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 9,472 ⟶ 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;</langsyntaxhighlight>
 
=={{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
 
<langsyntaxhighlight lang="sensetalk">
set bottleCount to 99
set bottleCount's format to "Words"
Line 9,491 ⟶ 12,274:
put empty
end repeat
</syntaxhighlight>
</lang>
Output:
<langsyntaxhighlight lang="sensetalk">
Ninety-Nine bottles of beer on the wall,
Ninety-Nine bottles of beer!
Line 9,515 ⟶ 12,298:
Take one down and pass it around,
Zero bottles of beer on the wall!
</syntaxhighlight>
</lang>
 
=={{header|SequenceL}}==
<langsyntaxhighlight lang="sequencel">import <Utilities/Conversion.sl>;
import <Utilities/Sequence.sl>;
 
Line 9,547 ⟶ 12,330:
plural := "s" when num /= 1 else "";
in
count ++ " bottle" ++ plural ++ " of beer";</langsyntaxhighlight>
 
=={{header|Set lang}}==
<langsyntaxhighlight Set_langlang="set_lang">set l 10
set s 32
set m 44
Line 9,646 ⟶ 12,429:
set k 1
set ? 9
> EOF</langsyntaxhighlight>
 
=={{header|Shen}}==
See [[99 Bottles of Beer/Lisp]]
 
=={{header|Shiny}}==
<langsyntaxhighlight lang="shiny">for 99 i:99-a
s: if i > 1 's' end
 
Line 9,662 ⟶ 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 :)"</langsyntaxhighlight>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">for i in (100 ^.. 0) {
var bottles = "#{i == 0 ? 'No' : i} bottle#{i == 1 ? '' : 's'}"
var sentence = "#{bottles} of beer on the wall" -> say
Line 9,672 ⟶ 12,458:
say "Take one down, pass it around\n"
}
}</langsyntaxhighlight>
 
'''Simpler:'''
<langsyntaxhighlight lang="ruby">for n in (100 ^.. 2) {
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 9,681 ⟶ 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."</langsyntaxhighlight>
 
=={{header|Simula}}==
<langsyntaxhighlight lang="simula">COMMENT HTTP://99-BOTTLES-OF-BEER.NET ;
COMMENT AUTHOR: TIM GOODWIN ;
COMMENT DATE: 04/20/05 ;
Line 9,719 ⟶ 12,506:
BEER(99);
END;
</syntaxhighlight>
</lang>
'''Simpler:'''
<langsyntaxhighlight lang="simula">COMMENT http://99-bottles-of-beer.net
author: Jack Leunissen
date: 03/10/07;
Line 9,750 ⟶ 12,537:
OUTIMAGE;
END;
</syntaxhighlight>
</lang>
 
=={{header|SkookumScript}}==
 
<langsyntaxhighlight lang="javascript">!bottles: (Integer num) [num.String += if num=1 [" bottle"] else [" bottles"]]
99.to 1
[
Line 9,762 ⟶ 12,549:
"Take one down, pass it around\n"
bottles(idx-1) " of beer on the wall\n")
]</langsyntaxhighlight>
 
 
=={{header|Slate}}==
<langsyntaxhighlight lang="slate">n@(Integer traits) bottleVerse
[| nprinted |
nprinted: n printString ; ' bottle' ; (n > 1 ifTrue: ['s'] ifFalse: ['']) ; ' of beer'.
Line 9,780 ⟶ 12,566:
].
 
99 bottles.</langsyntaxhighlight>
=={{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:
<langsyntaxhighlight lang="smalltalk">Smalltalk at: #sr put: 0 ; at: #s put: 0 !
sr := Dictionary new.
sr at: 0 put: ' bottle' ;
Line 9,799 ⟶ 12,610:
Transcript show: (sr at:s) ; show: (sr at:2) ; cr.
(v ~~ 0) ifTrue: [ Transcript show: (sr at:4) ; cr. ].
].</langsyntaxhighlight>
 
 
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.
<langsyntaxhighlight lang="smilebasic">DEF NUM(N)
IF N==-1 THEN
RETURN "99"
Line 9,851 ⟶ 12,698:
PRINT NUM(I-1);BTL(I-1);" of beer on the wall."
WAITPLAY 131
NEXT</langsyntaxhighlight>
 
=={{header|SNOBOL4}}==
<langsyntaxhighlight lang="snobol"> x = 99
again output = X " bottles of beer on the wall"
output = X " bottles of beer" ?eq(X,0) :s(zero)
Line 9,861 ⟶ 12,708:
zero output = "Go to store, get some more"
output = "99 bottles of beer on the wall"
end</langsyntaxhighlight>
 
===Function===
Line 9,867 ⟶ 12,714:
{{works with|CSnobol}}
Function version with string composition. Function returns one verse for x bottles. Correctly handles bottle/bottles.
<langsyntaxhighlight SNOBOL4lang="snobol4"> define('bottles(x)')
nl = char(13) char(10) ;* Win/DOS, change as needed
s2 = ' of beer'; s3 = ' on the wall'
Line 9,883 ⟶ 12,730:
n = 2
loop bottles(n); n = gt(n,0) n - 1 :s(loop)
end</langsyntaxhighlight>
 
Output:
Line 9,903 ⟶ 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}}==
 
<langsyntaxhighlight lang="sparkling">var bottles = 99;
 
do {
Line 9,915 ⟶ 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");</langsyntaxhighlight>
 
=={{header|SQL}}==
 
<syntaxhighlight lang="sql">
<lang SQL>
select
( 100 - level ) || ' bottle' || case when level != 99 then 's' end || ' of beer on the wall'
Line 9,929 ⟶ 12,798:
|| ( 99 - level ) || ' bottle' || case when level != 98 then 's' end || ' of beer on the wall'
from dual connect by level <= 99;
</syntaxhighlight>
</lang>
 
<syntaxhighlight lang="sql">
<lang SQL>
 
 
Line 9,963 ⟶ 12,832:
call bottles_( @bottles, @song);
select @song;
</syntaxhighlight>
</lang>
 
This Statement does also work with T-SQL, but only up to 32 beers
 
<syntaxhighlight lang="sql">
<lang SQL>
CREATE PROCEDURE bottles
@bottle_count int,
Line 10,015 ⟶ 12,884:
EXECUTE bottles 31, '';
 
</syntaxhighlight>
</lang>
 
<syntaxhighlight lang="sql">
<lang SQL>
 
/*These statements work in PostgreSQL (tested in 9.4)*/
Line 10,053 ⟶ 12,922:
ORDER BY n DESC;
 
</syntaxhighlight>
</lang>
 
=={{header|Squirrel}}==
<langsyntaxhighlight lang="squirrel">
function rec(bottles)
{
Line 10,072 ⟶ 12,941:
 
rec(99);
</syntaxhighlight>
</lang>
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">fun bottles 0 = ()
| bottles x = ( print (Int.toString x ^ " bottles of beer on the wall\n");
print (Int.toString x ^ " bottles of beer\n");
Line 10,081 ⟶ 12,950:
print (Int.toString (x-1) ^ " bottles of beer on the wall\n");
bottles (x-1)
)</langsyntaxhighlight>
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}}==
<langsyntaxhighlight lang="stata">program drink
local s s
forvalues i=`1'(-1)0 {
Line 10,125 ⟶ 13,025:
No more bottles of beer
Go to the store and buy some more
2 bottles of beer on the wall...</langsyntaxhighlight>
 
=={{header|Suneido}}==
<langsyntaxhighlight Suneidolang="suneido">i = 99
while (i > 0)
{
Line 10,138 ⟶ 13,039:
else
Print(i $ ' bottles of beer on the wall\n')
}</langsyntaxhighlight>
 
=={{header|Swift}}==
 
<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.")
}
</lang>
 
=={{header|SuperCollider}}==
<langsyntaxhighlight SuperColliderlang="supercollider">// post to the REPL directly
(
(99..0).do { |n|
Line 10,170 ⟶ 13,061:
}
)
</syntaxhighlight>
</lang>
 
=={{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}}==
 
<langsyntaxhighlight lang="symsyn">
BBW : ' Bottles of beer on the wall '
TOD : 'Take one down and pass it around '
Line 10,194 ⟶ 13,129:
goif | go back to if
endif
</syntaxhighlight>
</lang>
 
=={{header|Tailspin}}==
<langsyntaxhighlight lang="tailspin">
templates sayBottleCount
when <=1> do
'1 bottle' !
when <=0> do
'No bottles' !
otherwise
<>
'$; bottles' !
end sayBottleCount
 
99..1:-1 ->
'$->sayBottleCount; of beer on the wall,
Line 10,212 ⟶ 13,147:
Take one down, pass it around,
$:$ - 1 -> sayBottleCount; of beer on the wall.
 
' -> !OUT::write
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 10,243 ⟶ 13,178:
 
=={{header|TIScript}}==
<langsyntaxhighlight lang="javascript">
var beer = 99;
while (beer > 0)
Line 10,252 ⟶ 13,187:
stdout.printf( "%d bottles of beer on the wall\n", --beer );
}
</syntaxhighlight>
</lang>
 
=={{header|TMG}}==
Unix TMG:
<langsyntaxhighlight UnixTMGlang="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.> * };
Line 10,262 ⟶ 13,197:
rest: ( [n>=1?] decimal(n) | = { <no more> } );
plural: ( [n!=1?] = { <s> } | = { } );
n: 143;</langsyntaxhighlight>
 
=={{header|TorqueScript}}==
<syntaxhighlight lang="torquescript">
<lang TorqueScript>
for(%i = 99; %i >= 0; %i--)
{
Line 10,273 ⟶ 13,208:
echo(%n SPC (%i == 1 ? "bottle" : "bottles") SPC "of beer on the wall.");
}
</syntaxhighlight>
</lang>
 
=={{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}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
LOOP bottle=1,100
Line 10,292 ⟶ 13,282:
PRINT "Take one down, pass it around"
ENDLOOP
</syntaxhighlight>
</lang>
 
=={{header|TypeScript}}==
<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());</lang>
 
=={{header|TXR}}==
Line 10,318 ⟶ 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.
 
<langsyntaxhighlight lang="txr">@(next :list @(mapcar* (fun tostring) (range 99 -1 -1)))
@(collect)
@number
Line 10,349 ⟶ 13,319:
@ (end)
@ (end)
@(end)</langsyntaxhighlight>
 
To make the song repeat indefinitely, change the first line to:
 
<langsyntaxhighlight lang="txr">@(next :list @(mapcar* (fun tostring) (repeat (range 99 0 -1))))</langsyntaxhighlight>
 
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 10,392 ⟶ 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.
</lang>
<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 10,399 ⟶ 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 10,426 ⟶ 13,431:
end if
end for
</syntaxhighlight>
</lang>
 
=={{header|Ursala}}==
<langsyntaxhighlight Ursalalang="ursala">#import nat
 
# each function takes a natural number to a block of text
Line 10,455 ⟶ 13,460:
#show+
 
main = whole_song 99</langsyntaxhighlight>
 
=={{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">
<lang UTFool>
···
http://rosettacode.org/wiki/99_Bottles_of_Beer
Line 10,477 ⟶ 13,547:
s⦂ String: many > 1 ? "s" ! ""
return "⸨many⸩ bottle⸨s⸩ of beer"
</syntaxhighlight>
</lang>
 
=={{header|VV_(Vlang)}}==
<langsyntaxhighlight lang="v">[bottles
[newline '' puts].
[beer
Line 10,491 ⟶ 13,561:
tailrec].
 
99 bottles</langsyntaxhighlight>
 
=={{header|Vala}}==
<langsyntaxhighlight lang="vala">void main() {
uint bottles = 99;
do {
Line 10,512 ⟶ 13,582:
print(" of beer on the wall!\n\n");
} while (bottles != 0);
}</langsyntaxhighlight>
 
=={{header|VBA}}==
Line 10,523 ⟶ 13,593:
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.
<langsyntaxhighlight lang="vedit">RS(1, " 99")
RS(2, " bottles of beer")
RS(3, " on the wall")
Line 10,537 ⟶ 13,607:
} while (#1)
 
Return</langsyntaxhighlight>
 
=={{header|Verbexx}}==
<langsyntaxhighlight Verbexxlang="verbexx">fb @FN [x] { @IF (x == 1) then:{ 'bottle } else:{ 'bottles } };
 
@LOOP init:{@VAR n = 99} until:(n == 0)
Line 10,549 ⟶ 13,619:
@SAY "Take one down, pass it around" ;
@SAY n (@fb n) "of beer on the wall\n" ;
};</langsyntaxhighlight>
 
 
=={{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 10,556 ⟶ 13,649:
=={{header|Viua VM assembly}}==
 
<langsyntaxhighlight lang="asm">
.function: bottles_of_beer_text/1
.name: %iota number_of_bottles
Line 10,665 ⟶ 13,758:
.end
 
</syntaxhighlight>
</lang>
 
=={{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}}==
<langsyntaxhighlight lang="vox">
// translated from <http://rosettacode.org/wiki/99_Bottles_of_Beer#JavaScript>
 
Line 10,682 ⟶ 13,815:
(beer != 1 ? "s" : "") + " of beer on the wall\n"
);
</syntaxhighlight>
</lang>
 
=={{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 10,688 ⟶ 13,849:
 
=={{header|Whenever}}==
See [[99 Bottles of Beer/EsoLang]]
 
=={{header|Whitespace}}==
See [[99 Bottles of Beer/EsoLang]]
 
=={{header|Wortel}}==
<langsyntaxhighlight lang="wortel">!console.log @unlines ~!* 99..0 !? {
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"
}</langsyntaxhighlight>
 
=={{header|Wrapl}}==
<langsyntaxhighlight lang="wrapl">MOD Bottles;
 
IMP IO.Terminal USE Out;
Line 10,714 ⟶ 13,878:
Out:write(verse[2,0]@(String.T, "") + verse[1]);
 
END Bottles.</langsyntaxhighlight>
 
=={{header|Wren}}==
<langsyntaxhighlight lang="wren">for (i in 99...0) {
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")
}</langsyntaxhighlight>
 
=={{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 10,732 ⟶ 13,975:
=={{header|Xojo}}==
Place the following in the '''Run''' event handler of a Console application:
<langsyntaxhighlight lang="vb">Dim bottles As Integer = 99
While bottles > 0
Print(bottles.ToText + " bottles of beer on the wall,")
Line 10,740 ⟶ 13,983:
Print(bottles.ToText + " bottles of beer on the wall.")
Print ""
Wend</langsyntaxhighlight>
 
=={{header|XPL0}}==
<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;
]</lang>
 
=={{header|XPath}}==
Line 10,758 ⟶ 13,989:
A solution written in pure XPath 3.0 (using XSLT as a host language).
 
<langsyntaxhighlight lang="xml"><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:output method="text"/>
<xsl:template match="/">
Line 10,772 ⟶ 14,003:
/>
</xsl:template>
</xsl:stylesheet></langsyntaxhighlight>
 
=={{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 10,779 ⟶ 14,023:
To run, transform any document with this stylesheet (the input document is ignored).
 
<langsyntaxhighlight lang="xml"><?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="utf-8"/>
Line 10,852 ⟶ 14,096:
</xsl:template>
</xsl:stylesheet></langsyntaxhighlight>
 
===XSLT 3.0===
Line 10,865 ⟶ 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]
 
<langsyntaxhighlight lang="xml"><?xml version="1.0" ?>
<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 10,884 ⟶ 14,128:
</xsl:iterate>
</xsl:template>
</xsl:stylesheet></langsyntaxhighlight>
 
=={{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}}==
<langsyntaxhighlight Yabasiclang="yabasic">sub bottle$(i)
if i=0 return "no more bottles of beer"
if i=1 return "1 bottle of beer"
Line 10,895 ⟶ 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</langsyntaxhighlight>
 
 
=={{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 ===
<langsyntaxhighlight lang="yorick">bottles = 99;
while(bottles) {
write, format=" %d bottles of beer on the wall\n", bottles;
Line 10,906 ⟶ 14,201:
write, "Take one down, pass it around";
write, format=" %d bottles of beer on the wall\n\n", --bottles;
}</langsyntaxhighlight>
 
=== Vectorized version ===
<langsyntaxhighlight lang="yorick">song = "%d bottles of beer on the wall\n";
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;</langsyntaxhighlight>
 
 
=={{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}}==
<langsyntaxhighlight lang="zkl">[99..0,-1].pump(fcn(n){
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 10,930 ⟶ 14,248:
(n==0 and "No more bottles" or (n==1 and "1 bottle" or "" + n + " bottles"))
+ " of beer"
}</langsyntaxhighlight>
{{out}}
<pre>
41

edits