99 bottles of beer: Difference between revisions
PascalABC.NET
(PascalABC.NET) |
|||
(95 intermediate revisions by 35 users not shown) | |||
Line 44:
{{trans|Python}}
<
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")</
=={{header|360 Assembly}}==
Line 57:
=={{header|6800 Assembly}}==
See [[99 Bottles of Beer/Assembly]]
=={{header|68000 Assembly}}==
See [[99 Bottles of Beer/Assembly]]
Line 63 ⟶ 66:
=={{header|8th}}==
<
\ 99 bottles of beer on the wall:
: allout "no more bottles" ;
Line 84 ⟶ 87:
' beers 1 99 loop- bye
</syntaxhighlight>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program bootleBeer64.s */
Line 170 ⟶ 173:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
=={{header|ABAP}}==
<
DATA lv_no_bottles(2) TYPE n VALUE 99.
Line 189 ⟶ 192:
WRITE ' bottles of beer on the wall'.
WRITE /.
ENDDO.</
or (With ABAP 7.40)
<
DATA it_99_bottles TYPE TABLE OF string WITH EMPTY KEY.
Line 211 ⟶ 214:
cl_demo_output=>write( it_99_bottles ).
cl_demo_output=>display( ).
</syntaxhighlight>
=={{header|ABC}}==
<syntaxhighlight lang="abc">HOW TO RETURN bottles n:
SELECT:
n<0: RETURN "99 bottles"
n=0: RETURN "No more bottles"
n=1: RETURN "1 bottle"
n>1: RETURN "`n` bottles"
HOW TO SING VERSE n:
WRITE "`bottles n` of beer on the wall,"/
WRITE "`bottles n` of beer,"/
SELECT:
n=0: WRITE "Go to the store and buy some more,"/
n=1: WRITE "Take it down and pass it around,"/
n>1: WRITE "Take one down and pass it around,"/
WRITE "`bottles (n-1)` of beer on the wall."/
WRITE /
FOR n IN {0..99}:
SING VERSE 99-n</syntaxhighlight>
=={{header|ACL2}}==
See [[99 Bottles of Beer/Lisp]]
=={{header|Acornsoft Lisp}}==
See [[99 Bottles of Beer/Lisp]]
=={{header|Action!}}==
<
IF i=0 THEN
Print("No more")
Line 249 ⟶ 276:
FI
OD
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/99_bottles_of_beer.png Screenshot from Atari 8-bit computer]
Line 272 ⟶ 299:
=={{header|ActionScript}}==
<
{
trace(numBottles, " bottles of beer on the wall");
Line 278 ⟶ 305:
trace("Take one down, pass it around");
trace(numBottles - 1, " bottles of beer on the wall\n");
}</
=={{header|Ada}}==
===Simple version===
<
procedure Bottles is
Line 293 ⟶ 320:
New_Line;
end loop;
end Bottles;</
===Concurrent version===
with 1 task to print out the information and 99 tasks to specify the number of bottles
<
procedure Tasking_99_Bottles is
Line 334 ⟶ 361:
Task_List(I) := new Counter(I);
end loop;
end Tasking_99_Bottles;</
=={{header|Aime}}==
<
bottles = 99;
Line 346 ⟶ 373:
o_("Take one down, pass it around\n");
o_(bottles -= 1, " bottles of beer on the wall\n\n");
} while (bottles);</
=={{header|Algae}}==
<
# 99 Bottles of Beer on the Wall
# in Algae
Line 370 ⟶ 397:
}
}
</syntaxhighlight>
=={{header|ALGOL 60}}==
<
integer n;
Line 390 ⟶ 417:
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</
=={{header|ALGOL 68}}==
Line 396 ⟶ 423:
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}}
<!-- {{not works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - printf has been removed}} -->
<
FOR bottles FROM 99 TO 1 BY -1 DO
printf(($z-d" bottles of beer on the wall"l$, bottles));
Line 403 ⟶ 430:
printf(($z-d" bottles of beer on the wall"ll$, bottles-1))
OD
)</
=={{header|ALGOL-M}}==
<
BEGIN
Line 439 ⟶ 466:
END
</syntaxhighlight>
=={{header|AmigaE}}==
<
DEF t: PTR TO CHAR,
s: PTR TO CHAR,
Line 454 ⟶ 481:
IF i > 0 THEN WriteF(t)
ENDFOR
ENDPROC</
=={{header|Apache Ant}}==
Implementation in Apache Ant, due to the limitations of Ant, this requires ant-contrib for arithmetic operations and a dummy target to keep Ant from detecting the loop.
<
<project name="n bottles" default="99_bottles">
Line 499 ⟶ 526:
</target>
</project></
=={{header|Apex}}==
<
for(Integer i = 99; i=0; i--){
system.debug(i + ' bottles of beer on the wall');
Line 510 ⟶ 537:
system.debug('take one down, pass it around');
}
</syntaxhighlight>
=={{header|APL}}==
Line 545 ⟶ 572:
===Iteration===
<
set bottles to "bottles"
if beerCount < 99 then
Line 558 ⟶ 585:
log "Take one down, pass it around"
end
log "No more bottles of beer on the wall!"</
===Declaration===
<
on run
set localisations to ¬
Line 677 ⟶ 704:
on unwords(xs)
intercalate(space, xs)
end unwords</
=={{header|Arbre}}==
<syntaxhighlight lang="arbre">
bottle(x):
template: '
Line 704 ⟶ 731:
bottles(99) -> io
</syntaxhighlight>
=={{header|Argile}}==
<
let X be an int
Line 725 ⟶ 752:
.:on the wall:. -> text {
X>17 ? "on the wall", (X>1 ? "on the bwall", "in the buttle")
}</
=={{header|ARM Assembly}}==
Line 732 ⟶ 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.
<
HEY CHRISTMAS TREE is0
YOU SET US UP @NO PROBLEMO
Line 754 ⟶ 781:
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED</
=={{header|Arturo}}==
<
loop 99..1 'i [
Line 771 ⟶ 798:
]
else -> print "No more bottles of beer on the wall!"
]</
=={{header|AsciiDots}}==
<
/>*$_#-$_" bottles of beer on the wall, "-$_#-$" bottles of beer."\
|[-]1#-----" ,dnuora ti ssap dna nwod eno ekaT"_$-----------------/
Line 785 ⟶ 812:
| \-*--{=}-\\~$_#-$" bottles of beer on the wall."\
| \-#1/ \-/ |
\----------------------------------------------""$/</
=={{header|Astro}}==
<
(0) => "No more bottles"
(1) => "1 bottle"
Line 799 ⟶ 826:
Take one down, pass it around
{bottles n-1} of beer on the wall\n
"""</
=={{header|Asymptote}}==
<
// by Jjuanhdez, 05/2022
Line 821 ⟶ 848:
write("no more bottles of beer.");
write("Go to the store and buy some more,");
write(" 99 bottles of beer on the wall.");</
=={{header|ATS}}==
<syntaxhighlight lang="ats">//
#include
"share/atspre_staload.hats"
Line 852 ⟶ 879:
(* ****** ****** *)
implement main0 () = bottles (99)</
=={{header|AutoHotkey}}==
Line 866 ⟶ 893:
For example, just a sixpack:
<
function bb(n) {
Line 886 ⟶ 913:
}
print "Go to the store and buy some more!"
}</
{{out}}
Line 923 ⟶ 950:
Pauses are added to accommodate the small calculator screen so all of the text can be read.
<
While B
Disp B▶Dec," BOTTLES OF","BEER ON THE WALL"
Line 932 ⟶ 959:
Disp B▶Dec," BOTTLES OF","BEER ON THE WALL",i
getKeyʳ
End</
=={{header|Babel}}==
<
{b " bottles of beer" <
Line 952 ⟶ 979:
< }
-- At the prompt, type 'N beer !' (no quotes), where N is the number of stanzas you desire</
=={{header|BabyCobol}}==
<syntaxhighlight lang="cobol">
* Pointing out some interesting things:
* - BY 0 subclause of VARYING (illegal in some COBOL dialects)
* - PERFORM THROUGH with internal/external GO TOs
* - using non-reserved keywords (END, DATA)
* - ALTER (works the same way in COBOL)
* - fall-through from MANY-BOTTLES
* - the last NEXT SENTENCE does nothing (plays the role of EXIT)
IDENTIFICATION DIVISION.
PROGRAM-ID. 99 BOTTLES.
DATA DIVISION.
01 DATA PICTURE IS 999.
PROCEDURE DIVISION.
LOOP VARYING DATA FROM 99 BY 0
PERFORM COUNT-BOTTLES THROUGH END
DISPLAY DATA "bottles of beer"
DISPLAY "Take one down, pass it around"
SUBTRACT 1 FROM DATA
IF DATA = 1
THEN ALTER COUNT-BOTTLES TO PROCEED TO SINGLE-BOTTLE
END
PERFORM COUNT-BOTTLES THROUGH END
DISPLAY ""
END.
NO-BOTTLES-LEFT.
DISPLAY "No bottles of beer on the wall"
DISPLAY ""
DISPLAY "Go to the store and buy some more"
DISPLAY "99 bottles of beer on the wall".
STOP.
COUNT-BOTTLES.
GO TO MANY-BOTTLES.
SINGLE-BOTTLE.
DISPLAY DATA "bottle of beer on the wall".
GO TO NO-BOTTLES-LEFT.
MANY-BOTTLES.
DISPLAY DATA "bottles of beer on the wall".
END.
NEXT SENTENCE.
</syntaxhighlight>
=={{header|BASIC}}==
Line 960 ⟶ 1,029:
==={{header|BaCon}}===
See [[99 Bottles of Beer/Basic#BaCon]]
==={{header|BASIC256}}===
See [[99 Bottles of Beer/Basic]]
==={{header|BBC BASIC}}===
Line 966 ⟶ 1,038:
==={{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 986 ⟶ 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 995 ⟶ 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 1,001 ⟶ 1,094:
==={{header|Run BASIC}}===
See [[99 Bottles of Beer/Basic]]
==={{header|Sinclair ZX81 BASIC}}===
See [[99 Bottles of Beer/Basic]]
Line 1,010 ⟶ 1,106:
==={{header|TI-89 BASIC}}===
See [[99 Bottles of Beer/Basic]]
==={{header|Tiny BASIC}}===
See [[99 Bottles of Beer/Basic]]
Line 1,019 ⟶ 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 1,030 ⟶ 1,135:
<!--- works with C syntax highlighting --->
<syntaxhighlight lang="c">
const bottle = " bottle"
const plural = "s"
Line 1,174 ⟶ 1,279:
// vim: set syntax=c ts=4 sw=4 et:
</syntaxhighlight>
=={{header|Bc}}==
Line 1,180 ⟶ 1,285:
{{works with|GNU bc|1.06}}
<
while ( 1 ) {
print i , " bottles of beer on the wall\n";
Line 1,193 ⟶ 1,298:
print i , " bottle of beer on the wall\n";
print i , " bottle of beer\nTake it down, pass it around\nno more bottles of beer on the wall\n";
quit</
=={{header|BCPL}}==
<
let number(n) be
Line 1,227 ⟶ 1,332:
let start() be
for n = 99 to 1 by -1 do verse(n)</
=={{header|beeswax}}==
Line 1,233 ⟶ 1,338:
Straightforward implementation, displaying the full lyrics given on [ http://99-bottles-of-beer.net/ ]
<syntaxhighlight lang="beeswax">
> NN p
> d#_8~2~(P~3~.~1~>{` bottles of beer on the wall, `{` bottles of beer.`q
Line 1,242 ⟶ 1,347:
>N`No more bottles of beer on the wall, no more bottles of beer.`N q
;`.llaw eht no reeb fo selttob 99 ,erom emos yub dna erots eht ot oG`<
</syntaxhighlight>
A much more “economic” version that tries to avoid repetition at the price of complicated conditional jumps and self-modifying code that takes up more place than the actual strings themselves.
Output is the same as in the straightforward version.
<syntaxhighlight lang="beeswax">
#D@.9~2~@M.7~P9zE `N`p
DMM@.9@.~2~.++~5zE `n`>`o`p
Line 1,258 ⟶ 1,363:
>^^^^^^^^^; .# b XgNN < bM` ,dnuora ti ssap`<
d^^^^^^^^^^^^^^^^X~3~P(~2~8` ,erom emos yub dna erots eht ot`` oG`<
</syntaxhighlight>
=={{header|Befunge}}==
Line 1,264 ⟶ 1,369:
=={{header|BlitzMax}}==
<
repeat
Line 1,278 ⟶ 1,383:
print "1 bottle of beer."
print "Take it down, pass it around,"
print "No more bottles of beer on the wall!"</
=={{header|BlooP}}==
Output is always in caps in the interpreter I use, but I typed the input in correct case to spare those whose interpreter might do lowercase and don't want to have this song shouted at them ;D.
<
DEFINE PROCEDURE ''MINUS'' [A,B]:
BLOCK 0: BEGIN
Line 1,317 ⟶ 1,422:
BOTTLES[99];
</syntaxhighlight>
=={{header|Bracmat}}==
Line 1,331 ⟶ 1,436:
Code to save to BottlesOfBeer.bra:
<
See http://99-bottles-of-beer.net/}
Line 1,390 ⟶ 1,495:
new'X;
</syntaxhighlight>
=={{header|Brainf***}}==
Line 1,396 ⟶ 1,501:
=={{header|Brat}}==
<
p "#{n} bottles of beer on the wall, #{n} bottles of beer!"
p "Take one down, pass it around, #{n - 1} bottle#{true? n > 2 's' ''} of beer on the wall."
Line 1,402 ⟶ 1,507:
p "One bottle of beer on the wall, one bottle of beer!"
p "Take one down, pass it around, no more bottles of beer on the wall."</
=={{header|Bruijn}}==
<syntaxhighlight lang="bruijn">
:import std/Combinator .
:import std/Number .
:import std/String .
main [y [[=?0 case-end case-rec]] (+99)]
case-rec n ++ t1 ++ n ++ t2 ++ t3 ++ n ++ t1 ++ "\n" ++ (1 --0)
n number→string 0
t1 " bottles of beer on the wall\n"
t2 " bottles of beer\n"
t3 "Take one down, pass it around\n"
case-end empty
</syntaxhighlight>
=={{header|BQN}}==
<
{𝕨∾(@+10)∾𝕩}´{(•Fmt 𝕨)∾" "∾𝕩}´¨∾{
⟨
Line 1,413 ⟶ 1,533:
⟨𝕩-1,"bottle"∾(Pl 𝕩-1)∾" of beer on the wall"∾@+10⟩
⟩
}¨⌽1+↕99</
<code>•Fmt</code> is used to convert numbers to strings.
Line 1,424 ⟶ 1,544:
{{trans|C++}}
=== The simple solution ===
<
* 99 Bottles, C, KISS (i.e. keep it simple and straightforward) version
*/
Line 1,451 ⟶ 1,571:
return 0;
}</
=== A recursive solution ===
<
int main(int argc, char *argv[])
Line 1,470 ⟶ 1,590:
printf("%d bottle%c of beer on the wall\n\n", argc - 1, (argc - 1) == 1?'\0': 's');
return argc - 1;
}</
=== Code golf ===
<
main(){_=100;while(--_)printf("%i bottle%s of beer in the wall,\n%i bottle%"
"s of beer.\nTake one down, pass it round,\n%s%s\n\n",_,_-1?"s":"",_,_-1?"s"
:"",_-1?(char[]){(_-1)/10?(_-1)/10+48:(_-1)%10+48,(_-1)/10?(_-1)%10+48:2+30,
(_-1)/10?32:0,0}:"",_-1?"bottles of beer in the wall":"No more beers");}</
=== A preprocessor solution ===
Line 1,485 ⟶ 1,605:
Well, with the preprocessor, that's indeed possible:
<
#include <stdio.h>
Line 1,514 ⟶ 1,634:
(void) printf(SONG);
return EXIT_SUCCESS;
}</
An inspection of the generated executable proves that it indeed contains the complete text of the song in one block.
===The bottled version===
WYSIWYG (with correct plurals and can buy some more):<
#include<stdio.h>
char *d[16],y[]
Line 1,553 ⟶ 1,673:
'S',!(++u % 3) * 32+ 78) or
('.', puts("."))}return c;}
int main() {return p(0);}</
=={{header|C sharp|C#}}==
<
class Program
Line 1,584 ⟶ 1,704:
}
}
}</
=== C#6 Implementation ===
{{works with|C sharp|C#|6+}}
<
class Program
{
Line 1,598 ⟶ 1,718:
Console.WriteLine($"{f(i, true)}{f(i, false)}Take one down, pass it around\r\n{f(i - 1, true)}");
}
}</
=== Linq Implementation ===
{{works with|C sharp|C#|6+}}
<
using System.Linq;
Line 1,615 ⟶ 1,735:
).ToList().ForEach(x => Console.WriteLine(x));
}
}</
=== Flexible Version ===
<
using System.Globalization;
class Program
Line 1,658 ⟶ 1,778:
}
}
}</
=== Using Formatting ===
{{works with|C sharp|C#|3+}}
<
{
static void Main(string[] args)
Line 1,690 ⟶ 1,810:
}
}
}</
{{out}}
Line 1,713 ⟶ 1,833:
{{works with|C sharp|C#|3+}}
<
using System.Linq;
Line 1,733 ⟶ 1,853:
yield return String.Format(f, booze(i, true), booze(i, false), booze(i - 1, true));
}
}</
=== A Fun One ===
<
"Abita Amber",
"Adams Broadside Ale",
Line 1,866 ⟶ 1,986:
Console.WriteLine();
Console.ReadLine();
}</
=== Using recursion ===
<
{
if (numberOfBottles > 0)
Line 1,880 ⟶ 2,000:
BottlesSong(--numberOfBottles);
}
}</
=== Using a While Loop ===
<
{
int numBottles = 99;
Line 1,903 ⟶ 2,023:
WriteLine("No more bottles of beer on the wall, no more bottles of beer.");
WriteLine("Go to the store to buy some more, 99 bottles of beer on the wall...");
}</
=={{header|C/vFP16}}==
<syntaxhighlight
lang="cpp">#pragma SCH_64_16_IFP
#import <jobsched.c>
__attr(@canschedule)
volatile constricts async UVOID <__INVAR const T>base_000000 __PCON(
impure VFCTX_t^ ct_base,
impure MCHR_t^ sched_arg,
__LVAR <const T>XVF_fntype_t^ f,
<out VF_QSWitch_t>XVF_fn_t^ switchctx
) __ARGFILL {
VF_Xsched_ILock(ct_base, $->sched);
captured __VFObj <>VF_KeDbg^ ki = VF_Xg_KeDbg_Instance();
captured deferred <__VF_T_Auto>__VF_Auto^ vfke = copyof VF_KeDbg_GetRstream<MCHR_t^>(captures ki);
VF_Gsched_SOBFree(sched_arg);
VF_Gsched_Alloc_U16(65535);
VF_Msched_MChr_lim(1496);
VF_Osched_Begin();
VF_Fsched_Add2(%beer_000099);
VF_Xsched_IUnlock(ct_base, $->sched);
$switchctx(IMPURE_CTX, %beer_000099(%vfke));
}
__attr(@eUsesIo)
impure constricts UVOID synchronized beer_000099(
impure __noinline <MCHR_t^>RIGHTSTREAM_t^ outrs
) __NFILL {
pure UVOID^ uvid = __attr(@purify) $UVOID.;
while ( 99 > ((volatile NUM_t)^(NUM_t^)(uvid))++ ) {
VF_STM_Out_NUM((NUM_t^)uvid);
VF_STM_Out_x(__Dynamic C"bottles on the wall.\nPut one down, pass it around\n");
}
return $__;
}
</syntaxhighlight>
=={{header|C++}}==
=== The simple solution ===
{{works with|g++|4.8.1}}
<
using std::cout;
Line 1,919 ⟶ 2,082:
<< bottles - 1 << " bottles of beer on the wall\n\n";
}
}</
=== An object-oriented solution ===
Line 1,927 ⟶ 2,090:
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:
<
template<int max, int min> struct bottle_countdown
Line 1,954 ⟶ 2,117:
bottle_countdown<100, 1>::print();
return 0;
}</
=== A function template solution ===
Function templates are a different approach to template metaprogramming:
<
template<unsigned int N> void bottles(){
Line 1,978 ⟶ 2,141:
bottles<99>();
}
</syntaxhighlight>
=== A Recursive solution ===
<
using namespace std;
void rec(int bottles)
Line 2,001 ⟶ 2,164:
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:
<
#include <ostream>
Line 2,035 ⟶ 2,198:
std::cout << SONG;
return 0;
}</
=== Bottled Version ===
<
//Beer Song>,_
#include <iostream>
Line 2,075 ⟶ 2,238:
// by barrym 2011-05-01
// no bottles were harmed in the
// making of this program!!!</
=={{header|Ceylon}}==
<
String bottles(Integer count) =>
Line 2,090 ⟶ 2,253:
``bottles(i - 1)`` of beer on the wall!\n");
}
}</
=={{header|Chapel}}==
copied from http://99-bottles-of-beer.net/language-chapel-1215.html, with minor modifications for chapel 1.7
{{works with|Chapel|1.7.0}}
<syntaxhighlight lang="chapel">
/***********************************************************************
* Chapel implementation of "99 bottles of beer"
Line 2,164 ⟶ 2,327:
else "Take one down and pass it around, ";
}
</syntaxhighlight>
=={{header|Chef}}==
Line 2,171 ⟶ 2,334:
=={{header|Cind}}==
<
execute() {
Line 2,202 ⟶ 2,365:
return 0;
}
</syntaxhighlight>
=={{header|Clay}}==
<
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
Line 2,226 ⟶ 2,389:
println(join("\n", mapped(getRound, reversed(range(100)))));
}
</syntaxhighlight>
=={{header|Clio}}==
<
n -> if = 0: 'no more bottles'
elif = 1: n + ' bottle'
Line 2,239 ⟶ 2,402:
'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'</
=={{header|CLIPS}}==
<
(bottles 99))
Line 2,261 ⟶ 2,424:
(printout t "Take one down, pass it around," crlf)
(printout t (bottle-count (- ?count 1)) " on the wall." crlf crlf)
(if (> ?count 1) then (assert (bottles (- ?count 1)))))</
=={{header|Clojure}}==
<
(str num " bottles of beer on the wall\n"
num " bottles of beer\n"
Line 2,276 ⟶ 2,439:
(print (lyrics))</
Or, using cl-format:
{{trans|Common Lisp}}
<
true
"~{~[~^~]~:*~D bottle~:P of beer on the wall~%~:*~D bottle~:P of beer
Take one down, pass it around,~%~D bottle~:P~:* of beer on the wall.~2%~}"
(range 99 0 -1))</
=={{header|CLU}}==
<
if n<0 then return("99 bottles")
elseif n=0 then return("No more bottles")
Line 2,321 ⟶ 2,484:
stream$puts(po, verse(n))
end
end start_up</
=={{header|COBOL}}==
{{works with|OpenCOBOL|1.1}}
Free form version.
<
program-id. ninety-nine.
environment division.
Line 2,429 ⟶ 2,592:
100-end.
end-program.</
Another free-form version, without using <code>DISPLAY NO ADVANCING</code>.
<
program-id. ninety-nine.
environment division.
Line 2,553 ⟶ 2,716:
100-end.
end-program.</
A more concise version that adheres to the minimum guidelines. Leading zeros are not suppressed. (OpenCOBOL - 1.1.0)
<
data division.
working-storage section.
Line 2,571 ⟶ 2,734:
add 1 to cnt
display space
end-perform.</
=={{header|CoffeeScript}}==
<
bottlesOfBeer = (n) ->
"#{n} bottle#{if n is 1 then '' else 's'} of beer"
Line 2,584 ⟶ 2,747:
#{bottlesOfBeer n - 1} on the wall
\n""" for n in [99..1]
</syntaxhighlight>
With completely different approach...
<
x=''
x += [j,j-1,'\nTake one down, pass it around\n'," bottles of beer",' on the wall\n'][i] for i in [0,3,4,0,3,2,1,3,4]
console.log x.replace /(1.+)s/g, '$1'
</syntaxhighlight>
or as a one liner...
<
or another completely different one liner
<
=={{header|ColdFusion}}==
=== Classic tag based CFML ===
<
<cfloop index="x" from="99" to="0" step="-1">
<cfset plur = iif(x is 1,"",DE("s"))>
Line 2,612 ⟶ 2,775:
#iif(x is 1,DE("No more"),"x-1")# bottle#iif(x is 2,"",DE("s"))# of beer on the wall<br><br>
</cfloop>
</cfoutput></
or if you prefer: (identical output, grammatically correct to the last stanza)
=== CFScript ===
<
for (x=99; x gte 1; x--) {
plur = iif(x==1,'',DE('s'));
WriteOutput("#x# bottle#plur# of beer on the wall<br>#x# bottle#plur# of beer<br>Take one down, pass it around<br>#iif(x is 1,DE('No more'),'x-1')# bottle#iif(x is 2,'',DE('s'))# of beer on the wall<br><br>");
}
</cfscript></
=={{header|Comal}}==
<
0020 itone$(0):="one";itone$(1):="it"
0030 FOR b#:=99 TO 1 STEP -1 DO
Line 2,646 ⟶ 2,809:
0210 ENDCASE
0220 ENDPROC bottles
0230 END</
=={{header|Comefrom0x10}}==
<
remaining = 99
one_less_bottle = remaining
Line 2,667 ⟶ 2,830:
comefrom if one_less_bottle is 0
'No more bottles of beer on the wall'</
{{out}}
Line 2,689 ⟶ 2,852:
=={{header|Cowgol}}==
<
sub Bottles(n: uint8) is
Line 2,724 ⟶ 2,887:
Verse(verse);
verse := verse - 1;
end loop;</
{{out}}
Line 3,224 ⟶ 3,387:
=={{header|Crystal}}==
<
puts "#{n} bottle#{n > 1 ? "s" : ""} of beer on the wall"
puts "#{n} bottle#{n > 1 ? "s" : ""} of beer"
Line 3,231 ⟶ 3,394:
end
puts "No more bottles of beer on the wall"
</syntaxhighlight>
=={{header|D}}==
Line 3,240 ⟶ 3,403:
Based on Steward Gordon's code at: [http://99-bottles-of-beer.net/language-d-721.html 99-bottles-of-beer.net].
<
void main() {
Line 3,259 ⟶ 3,422:
writeln("Go to the store and buy some more,");
writeln("99 bottles of beer on the wall.");
}</
=== CTFE Solution ===
Line 3,265 ⟶ 3,428:
CTFE (Compile-Time Function Execution) is a feature of D that allows for pure functions of arbitrary complexity to be completely evaluated at compile time when every parameter is known. Note that this is distinct from the template meta-programming tricks used by some other languages, and this bottles() function could just as easily be executed during run-time. The compiled result of this program simply prints the pre-generated lyrics to the song, using a standard compiler pragma directive.
<
string bottles(in size_t num) pure {
Line 3,288 ⟶ 3,451:
pragma(msg, 99.bottles);
void main() {}</
=== Template Meta-Programming Solution ===
Line 3,294 ⟶ 3,457:
Uses D template meta-programming and recursion to pre-generate the song lyrics and prints it at compile via pragma(msg,...)
<syntaxhighlight lang="d">
module bottles;
Line 3,316 ⟶ 3,479:
void main(){}
</syntaxhighlight>
=={{header|Dart}}==
// Making use of polymorphism
<
BeerSong beerSong = BeerSong();
//pass a 'starting point' and 'end point' as parameters respectively
Line 3,380 ⟶ 3,543:
}
}</
=={{header|Dc}}==
Line 3,386 ⟶ 3,549:
{{works with|GNU dc}}
{{works with|OpenBSD dc}}
<syntaxhighlight lang="dc">[
dnrpr
dnlBP
Line 3,414 ⟶ 3,577:
]P
[no more bottles of beer on the wall
]P</
Similar to the program above, but without 'n' and 'r' commands. It prints the numbers on separate lines than the strings.
{{works with|AT&T dc}}
<syntaxhighlight lang="dc">[
plAP
plBP
Line 3,450 ⟶ 3,613:
]P
[no more bottles of beer on the wall
]P</
=={{header|DBL}}==
<syntaxhighlight lang="text">;
;===============================================================================
; Oringinal Author: Bob Welton (welton@pui.com)
Line 3,504 ⟶ 3,667:
DISPLAY (1,"99 Bottles of Beer on the wall,",10,10,10)
CLOSE 1
STOP</
=={{header|Delphi}}==
Line 3,510 ⟶ 3,673:
=={{header|Draco}}==
<
if b=0 then write("No more") else write(b) fi;
write(" bottle");
Line 3,531 ⟶ 3,694:
byte v;
for v from 99 downto 1 do verse(v) od
corp</
=={{header|Dyalect}}==
{{trans|Swift}}
<
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.")
}</
=={{header|Dylan}}==
<
define method bottles (n :: <integer>)
for (n from 99 to 1 by -1)
Line 3,551 ⟶ 3,714:
n, n, n - 1);
end
end method</
=={{header|Déjà Vu}}==
<
if = 1 i "" "s"
Line 3,570 ⟶ 3,733:
!print "Go to the store and buy some more, 99 bottles of beer on the wall."
bottles 99</
=={{header|DIBOL-11}}==
<syntaxhighlight lang="dibol-11">
;
;===============================================================================
Line 3,647 ⟶ 3,810:
</syntaxhighlight>
=={{header|E}}==
<
return switch (n) {
match ==0 { "No bottles" }
Line 3,662 ⟶ 3,825:
${bottles(n.previous())} of beer on the wall.
`)
}</
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func$ bottle num .
if num = 1
return "bottle"
.
return "bottles"
.
#
i = 99
repeat
print i & " " & bottle i & " of beer on the wall"
print i & " " & bottle i & " of beer"
print "Take one down, pass it around"
i -= 1
until i = 0
print i & " " & bottle i & " of beer on the wall"
print ""
.
print "No more bottles of beer on the wall"
</syntaxhighlight>
=={{header|ECL}}==
<syntaxhighlight lang="ecl">
Layout := RECORD
UNSIGNED1 RecID1;
Line 3,688 ⟶ 3,873:
Rev := NORMALIZE(Beers,5,XF(LEFT,COUNTER));
OUTPUT(SORT(Rev,-Recid1,-RecID2),{txt},ALL);
</syntaxhighlight>
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">module Bottles {
void run() {
function String(Int) num = i -> i==0 ? "No" : i.toString();
function String(Int) bottles = i -> i==1 ? "bottle" : "bottles";
@Inject Console console;
for (Int remain : 99..1) {
console.print($|{num(remain)} {bottles(remain)} of beer on the wall
|{num(remain)} {bottles(remain)} of beer
|Take one down, pass it around
|{num(remain-1)} {bottles(remain-1)} of beer on the wall
|
);
}
}
}</syntaxhighlight>
=={{header|Egel}}==
<syntaxhighlight lang="egel">
import "prelude.eg"
import "io.ego"
Line 3,708 ⟶ 3,911:
def main = print_rhyme 99
</syntaxhighlight>
=={{header|EGL}}==
<
function main()
Line 3,732 ⟶ 3,935:
end
end
end</
=={{header|Eiffel}}==
<
class
APPLICATION
Line 3,776 ⟶ 3,979:
end
</syntaxhighlight>
An alternative version written using the across-loop construct.
<
output_lyrics
-- Output the lyrics to 99-bottles-of-beer.
Line 3,803 ⟶ 4,006:
end
</syntaxhighlight>
=={{header|Ela}}==
<
beer 1 = "1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around"
Line 3,815 ⟶ 4,018:
++" bottles of beer\nTake one down, pass it around\n"
map beer [99,98..0]</
=={{header|Elan}}==
<syntaxhighlight lang="elan">INT VAR number of bottles;
PROCEDURE print how many bottles are on the wall (INT CONST number):
print number;
print bottle;
print trailing text.
print number:
IF number = 0 THEN
put ("No")
ELSE
put (number)
END IF.
print bottle:
out ("Bottle");
IF no <> 1 THEN
out ("s")
END IF.
print trailing text:
out (" of beer").
END PROCEDURE print how many bottles are on the wall;
say hello;
print song;
say goodbye.
say hello:
putline ("99 Bottles of Beer");
putline ("==================");
line.
print song:
FOR number of bottles FROM 99 DOWNTO 1 REPEAT
print first line;
print second line;
print third line
END REPEAT.
say goodbye:
line;
putline ("=====================");
putline ("You need a ride home?");
line.
print first line:
print how many bottles are on the wall (number of bottles);
out (" on the wall, ");
print how many bottles are on the wall (number of bottles);
line.
print second line:
putline ("Take one down and pass it around,").
print third line:
print how many bottles are on the wall (number of bottles - 1);
putline (" on the wall");
line.</syntaxhighlight>
=={{header|Elena}}==
ELENA
<
import extensions;
import extensions'routines;
Line 3,829 ⟶ 4,093:
= self.toPrintable() + (self != 1).iif(" bottles"," bottle");
bottleEnumerator() = new Variable(self).doWith::(n)
{
^ new Enumerator
Line 3,835 ⟶ 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
reset() {}
enumerable() =
}
};
Line 3,852 ⟶ 4,116:
var bottles := 99;
bottles.bottleEnumerator().forEach
}</
{{out}}
<pre>
Line 3,883 ⟶ 4,147:
=={{header|Elixir}}==
<
def run do
Enum.each 99..1, fn idx ->
Line 3,898 ⟶ 4,162:
end
Bottles.run</
=={{header|Elm}}==
<
import Html
Line 3,927 ⟶ 4,191:
|> Html.p []
)
|> Html.div []</
=={{header|Emacs Lisp}}==
<
(while (> i 0)
(message "%d bottles of beer on the wall" i)
Line 3,936 ⟶ 4,200:
(message "Take one down, pass it around")
(message "%d bottles of beer on the wall" (1- i))
(setq i (1- i))))</
=={{header|EMal}}==
This version writes the lyrics as described here: https://99-bottles-of-beer.net/lyrics.html
<syntaxhighlight lang="emal">
type NinetynineBottles
int DEFAULT_BOTTLES_COUNT = 99
model
int initialBottlesCount, bottlesCount
new by int =bottlesCount
me.initialBottlesCount = bottlesCount
end
fun subject = <|when(me.bottlesCount == 1, "bottle", "bottles")
fun bottles = <|when(me.bottlesCount == 0, "no more", text!me.bottlesCount)
fun goToWall = void by block
text line = me.bottles() + " " + me.subject() + " of beer on the wall, " +
me.bottles() + " " + me.subject() + " of beer."
if me.bottlesCount == 0 do line[0] = line[0].upper() end # text can be modified
writeLine(line)
end
fun takeOne = logic by block
if --me.bottlesCount < 0 do return false end # cannot take a beer down
writeLine("Take one down and pass it around, " + me.bottles() +
" " + me.subject() + " of beer on the wall.")
writeLine()
return true
end
fun goToStore = void by block
writeLine("Go to the store and buy some more, " + me.initialBottlesCount +
" bottles of beer on the wall.")
end
fun play = void by block
for ever
me.goToWall()
if not me.takeOne()
me.goToStore()
break
end
end
end
end
NinetynineBottles(when(Runtime.args.length > 0, int!Runtime.args[0], DEFAULT_BOTTLES_COUNT)).play()
</syntaxhighlight>
The output for two bottles of beer is as follows.
{{out}}
<pre>
2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.
1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.
No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 2 bottles of beer on the wall.
</pre>
=={{header|Erlang}}==
<
-export([sing/0]).
-define(TEMPLATE_0, "~s of beer on the wall, ~s of beer.~nGo to the store and buy some more, 99
Line 3,977 ⟶ 4,295:
spawn_singer(Bottle),
sing_verse(Bottle)
end.</
=={{header|Euphoria}}==
{{works with|Euphoria|4.0.0}}
<
bottles = "bottles",
bottle = "bottle"
Line 4,008 ⟶ 4,326:
for a = 99 to 1 by -1 do
beers (a)
end for</
<
include std/console.e
Line 4,026 ⟶ 4,344:
howmany[(beer>2)+3]
})
end for</
<
include std/console.e
Line 4,047 ⟶ 4,365:
display(stanza[1]&"\n",{bottles})
until bottles = 0
end loop</
=={{header|Extended BrainF***}}==
Line 4,053 ⟶ 4,371:
=={{header|F_Sharp|F#}}==
<
let rec bottles n =
let (before, after) = match n with
Line 4,064 ⟶ 4,382:
printfn "%d %s of beer on the wall\n" (n - 1) after
if n > 1 then
bottles (n - 1)</
=={{header|Factor}}==
<
: bottle ( -- quot )
Line 4,088 ⟶ 4,406:
1 [a,b] bottle each last-verse ;
! Usage: 99 bottles</
=={{header|Falcon}}==
<
> i, " bottles of beer on the wall"
> i, " bottles of beer"
> "Take one down, pass it around"
> i-1, " bottles of beer on the wall\n"
end</
A more robust version to handle plural/not plural conditions
<
plural = (i != 1) ? 's' : ""
> @ "$i bottle$plural of beer on the wall"
Line 4,105 ⟶ 4,423:
> "Take one down, pass it around"
> i-1, @ " bottle$plural of beer on the wall\n"
end</
=={{header|FALSE}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|Fe}}==
<syntaxhighlight lang="clojure">
(= n 99)
(while (< 0 n)
(print n "bottles of beer on the wall")
(print n "bottles of beer")
(print "Take one down, pass it around")
(= n (- n 1))
(print n "bottles of beer on the wall\n"))
</syntaxhighlight>
=={{header|ferite}}==
copied from [http://99-bottles-of-beer.net/language-ferite-1281.html?PHPSESSID=b563ec9a2791f6c3cc917c22b17dc542 99-bottles-of-beer.net].
<
number bottles = 99;
Line 4,132 ⟶ 4,461:
looping = counter.invoke();
Console.println("${bottles} bottles of beer on the wall.");</
=={{header|Fexl}}==
<
\suffix=(\n eq n 1 "" "s")
\sing_count=(\n put [n " bottle" (suffix n) " of beer"])
Line 4,152 ⟶ 4,481:
)
sing 3
</syntaxhighlight>
{{out}}
Line 4,174 ⟶ 4,503:
=={{header|FOCAL}}==
<
01.15 D 2;T " OF BEER ON THE WALL,",!
01.20 D 2;T " OF BEER,",!
Line 4,219 ⟶ 4,548:
04.26 T "6";R
04.27 T "7";R
04.28 T "8";R</
=={{header|Forth}}==
<
:noname ." 1 bottle" ;
:noname ." no more bottles" ;
Line 4,235 ⟶ 4,564:
: verses begin cr .verse ?dup 0= until ;
99 verses</
Version 2: create a beer language and write the program
<
: BOTTLES ( n -- )
DUP
Line 4,272 ⟶ 4,601:
ONELESS BOTTLES OF BEER ON THE WALL .
ANOTHER
HANGOVER ;</
Forth Console Output
<
2 bottles of beer on the wall,
2 bottles of beer ,
Line 4,286 ⟶ 4,615:
No more bottles of beer on the wall.
ok</
=={{header|Fortran}}==
===F90 version===
<
implicit none
Line 4,313 ⟶ 4,642:
end do
end program bottlestest</
===MPI version===
<
implicit none
Line 4,343 ⟶ 4,672:
call mpi_finalize(ierr)
end program bottlesMPI</
Usage:
Line 4,351 ⟶ 4,680:
===Fortran 2003/2008 OOP version===
Works with GNU gfortran 5.0.0 and Intel ifort 15.0.2
<
module song_typedefs
implicit none
Line 4,484 ⟶ 4,813:
end program bottles_song
</syntaxhighlight>
=={{header|Frege}}==
Line 4,491 ⟶ 4,820:
{{Works with|Frege|3.21.586-g026e8d7}}
<
main = mapM_ (putStrLn . beer) [99, 98 .. 0]
Line 4,499 ⟶ 4,828:
++ show v
++ " bottles of beer\nTake one down, pass it around\n"
++ head (lines $ beer $ v-1) ++ "\n"</
=={{header|friendly interactive shell}}==
Line 4,506 ⟶ 4,835:
=={{header|Frink}}==
Frink tracks units of measure through all calculations. It has a large library of built-in units of measure, including volume. The following program prints out the remaining volume of beer (assuming we start with 99 bottles of beer, each containing 12 fluid ounces) in different random units of volume, never repeating a unit.
<
units = array[units[volume]]
showApproximations[false]
Line 4,524 ⟶ 4,853:
getBottleString[n, unit] := format[n*12 floz, unit, 6] + "s"
</syntaxhighlight>
Sample randomized output:
Line 4,563 ⟶ 4,892:
=={{header|FunL}}==
<
numbers = {1:'one', 2:'two', 3:'three', 4:'four', 5:'five', 6:'six', 7:'seven',
8:'eight', 9:'nine', 10:'ten', 11:'eleven', 12:'twelve'}
Line 4,592 ⟶ 4,921:
+ ' of beer on the wall.\n')
for i <- 99..0 by -1 do println( verse(i) )</
=={{header|FutureBasic}}==
<
include "NSLog.incl"
Line 4,606 ⟶ 4,935:
for i = 99 to 1 step -1
NSLog( @"%ld%@%ld%@%@%ld%@\n", i, a, i, b, c, i -1, a )
next
HandleEvents
</syntaxhighlight>
=={{header|Gambas}}==
Implementation of the code '99 bottles of beer' written in Visual Basic. Code tested in Gambas 3.15.2
<
Public Const bottlesofbeer As String = " bottles of beer."
Line 4,651 ⟶ 4,980:
Print "99" & bottlesofbeer & onthewall
End</
=={{header|GAP}}==
<
local line, i, j, u;
line := function(n)
Line 4,675 ⟶ 5,004:
fi;
od;
end;</
=={{header|GDScript}}==
{{works with|Godot|4.0}}
<syntaxhighlight lang="gdscript">
extends MainLoop
# Represents a count of bottles
class Bottles:
var count := 99
func take(n: int = 1) -> void:
count -= n
func _to_string() -> String:
match count:
0: return "No more bottles"
1: return "1 bottle"
_: return "%s bottles" % count
func _process(_delta: float) -> bool:
var bottles := Bottles.new()
while bottles.count > 0:
print("%s of beer on the wall" % bottles)
print("%s of beer" % bottles)
print("Take one down, pass it around")
bottles.take()
print("%s of beer on the wall" % bottles)
# Seperate paragraphs
if bottles.count > 0:
print()
return true # Makes the program exit
</syntaxhighlight>
===Silly node-tree version===
This uses the node's children as the display method (which can be viewed in-editor with the remote tab).
<syntaxhighlight lang="gdscript">
extends Node
@export var alcoholism: int = 99
func _ready():
# Add the lyrics as child nodes
var padding := "" # Avoid name clashes by adding spaces
for bottleCount in range(alcoholism, 0, -1):
# Seperate paragraphs with blank nodes
if bottleCount < alcoholism:
add_lyric(padding)
add_lyric("%s of beer on the wall" % [_formatBottles(bottleCount)])
add_lyric("%s of beer" % [_formatBottles(bottleCount)])
add_lyric("Take one down, pass it around" + padding)
add_lyric("%s of beer on the wall " % [_formatBottles(bottleCount - 1)]) # Extra space for name clash avoidance
padding += " " # Add spaces so the names don't clash
func _formatBottles(bottleCount: int) -> String:
return "%d bottle%s" % [bottleCount, "" if bottleCount == 1 else "s"]
func add_lyric(lyric: String) -> void:
var new_child := Node.new()
new_child.name = lyric
add_child(new_child)
</syntaxhighlight>
=={{header|Genie}}==
<
def plural(n:uint):string
return (n == 1) ? "" : "s"
Line 4,691 ⟶ 5,084:
--bottles
print "%s bottle%s of beer on the wall\n", no(bottles), plural(bottles)
while bottles != 0</
{{out}}
Line 4,707 ⟶ 5,100:
=={{header|gnuplot}}==
<
print sprintf("%i bottles of beer on the wall", bottles)
print sprintf("%i bottles of beer", bottles)
Line 4,714 ⟶ 5,107:
print sprintf("%i bottles of beer on the wall", bottles)
print ""
if (bottles > 0) reread</
=={{header|Go}}==
===No sense of humor===
<
import "fmt"
Line 4,740 ⟶ 5,133:
fmt.Printf("%s of beer on the wall\n", bottles(i-1))
}
}</
===Typoglycemic===
With code from RC tasks Number names, Knuth shuffle.
<
import (
Line 4,823 ⟶ 5,216:
w := strings.Fields(p[:1] + string(a) + p[len(p)-1:])
return strings.Join(w, " ")
}</
{{out}}
Things start out pretty well...
Line 4,865 ⟶ 5,258:
=={{header|Go!}}==
Copied from [http://99-bottles-of-beer.net/language-go!-289.html The 99 Bottles of Beer web site] with a minor bug fix.
<
-- 99 Bottles of Beer in Go!
-- John Knottenbelt
Line 4,895 ⟶ 5,288:
bottles(1) => "1 bottle of beer".
bottles(i) => i^0 <> " bottles of beer".
}</
=={{header|Golfscript}}==
<
=={{header|Golo}}==
<
augment java.lang.Integer {
Line 4,919 ⟶ 5,312:
println("--------------------------------------")
})
}</
=={{header|Gosu}}==
<
for (i in 99..0) {
Line 4,934 ⟶ 5,327:
}
</syntaxhighlight>
=={{header|Groovy}}==
===Basic Solution===
With a closure to handle special cardinalities of bottles.
<
99.downto(1) { i ->
Line 4,948 ⟶ 5,341:
${bottles(i-1)} of beer on the wall
"""
}</
=== Single Print Version ===
Uses a single print algorithm for all four lines. Handles cardinality on bottles, uses 'No more' instead of 0.
<
def (m,d) = [it%3,(int)it/3]
print "${m==1?'\n':''}${d?:'No more'} bottle${d!=1?'s':''} of beer" +
"${m?' on the wall':'\nTake one down, pass it around'}\n"
}</
===Bottomless Beer Solution===
Using more closures to create a richer lyrical experience.
<
def initialState = {
Line 4,989 ⟶ 5,382:
}
// Thread.sleep(1000)
// }</
=={{header|GUISS}}==
Line 4,995 ⟶ 5,388:
We will just use the calculator and keep taking one off. We do not get the full text here, but the number of the calculator shows how many bottles we still have left to drink:
<
Button:[hyphen],Button:1,Button:[equals],Button:[hyphen],Button:1,Button:[equals],
Button:[hyphen],Button:1,Button:[equals],Button:[hyphen],Button:1,Button:[equals],
Button:[hyphen],Button:1,Button:[equals],Button:[hyphen],Button:1,Button:[equals],
Button:[hyphen],Button:1,Button:[equals],Button:[hyphen],Button:1,Button:[equals]
</syntaxhighlight>
We haven't drank all of the bottles at this point, but we can keep going, if we want.
=={{header|Halon}}==
<
$x = 99;
while ($x > 0) {
Line 5,017 ⟶ 5,410:
else
echo "No more bottles of beer on the wall!";
}</
=={{header|Haskell}}==
Line 5,023 ⟶ 5,416:
A relatively concise solution:
<
beer 1 = "1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around"
beer 0 = "better go to the store and buy some more."
Line 5,029 ⟶ 5,422:
++ show v
++" bottles of beer\nTake one down, pass it around\n"
++ head (lines $ beer $ v-1) ++ "\n"</
====List comprehension====
As a list comprehension:
<
main = putStr $ concat
Line 5,048 ⟶ 5,441:
num n = show n
s 1 = ""
s _ = "s"</
====Writer monad and Template Haskell====
Another version, which uses a Writer monad to collect each part of the song. It also uses Template Haskell to generate the song at compile time.
<
-- build with "ghc --make beer.hs"
module Main where
Line 5,080 ⟶ 5,473:
in return $ LitE $ StringL $ song)
main = putStr songString</
====Avoiding append by spelling bottle backwards====
Is there something just a little prickly and displeasing about (++) ?
Monoid (<>) is less spiky, but neither is needed when 'bottle' is written backwards.
<
[location, distribution, solution] =
[ "on the wall",
Line 5,115 ⟶ 5,508:
main :: IO ()
main = putStrLn $ unlines (incantation <$> [99, 98 .. 0])</
=={{header|Haxe}}==
=== Simple solution ===
<
{
static public function main()
Line 5,151 ⟶ 5,544:
}
}
}</
=== Macro solution ===
Line 5,157 ⟶ 5,550:
Let's generate that print with macro.
<
static public function main () : Void {
Line 5,189 ⟶ 5,582:
}
}</
=={{header|hexiscript}}==
<
let bottle " bottles of "
if amount = 0; let amount "No more"
Line 5,213 ⟶ 5,606:
println take "one" "down" + pass "it" "around"
println bottles (--amount) "beer" "on the wall\n"
endwhile</
=={{header|HicEst}}==
<
WRITE() x , "bottles of beer on the wall"
BEEP("T16 be be be bH bH bH be be be 2be ")
Line 5,228 ⟶ 5,621:
WRITE() x , "bottles of beer on the wall"
BEEP("2p #A #A #A c c d #d #d #d 2#d 2p")
ENDDO</
=={{header|HolyC}}==
The default is 99 bottles, but it can be modified by the parameter.
<
// This is made I64 rather than U64
// Because, a U64 would overflow
Line 5,262 ⟶ 5,655:
// Calls the function, which goes to the default parameters
BottlesOfBeer;
</syntaxhighlight>
=={{header|Hoon}}==
<syntaxhighlight lang="hoon">
:- %say
|= [* * [bottles=_99 ~]]
:- %noun
^- wall
=/ output `(list tape)`~
|-
?: =(1 bottles)
%- flop
:- "1 bottle of beer on the wall"
:- "Take one down, pass it around"
:- "1 bottle of beer"
:- "1 bottle of beer on the wall"
output
%= $
bottles (dec bottles)
output
:- "{<bottles>} bottles of beer on the wall"
:- "Take one down, pass it around"
:- "{<bottles>} bottles of beer"
:- "{<bottles>} bottles of beer on the wall"
output
==
</syntaxhighlight>
=={{header|Hope}}==
El código es de Wolfgang Lohmann (wlohmann@informatik.uni-rostock.de)
<
dec i2c : num -> char;
dec i2s : num -> list(char);
Line 5,299 ⟶ 5,718:
"Take one down, pass it around. "),
beer(y))
where y== x-1;</
Line 5,306 ⟶ 5,725:
=={{header|Huginn}}==
<
exec huginn --no-argv -E "${0}" "${@}"
#! huginn
Line 5,329 ⟶ 5,748:
);
return ( 0 );
}</
=={{header|HyperTalk}}==
El código es de Eric Carlson eric@bungdabba.com
<
BottlesOfBeer 99
end BeerSong99
Line 5,372 ⟶ 5,791:
return bottleCount && "bottles"
end if
end BottleString</
=={{header|Icon}} and {{header|Unicon}}==
The default is 99 bottles, but you can change this on the command line for
really long trips...
<
numBeers := integer(args[1]) | 99
drinkUp(numBeers)
Line 5,403 ⟶ 5,822:
write("Go to the store and buy some more, ",
beerMax," bottles of beer on the wall.")
end</
=={{header|IDL}}==
<
for i=1,99 do begin
Line 5,415 ⟶ 5,834:
End
</syntaxhighlight>
Since in IDL "FOR"-loops are the embodiment of pure evil (see http://www.idlcoyote.com/tips/forloops.html and http://www.idlcoyote.com/tips/forloops2.html) there is also a loop free IDL way:
<
b=(reverse(shift(sindgen(100),-1)))[1:99]
b2=reverse(sindgen(99))
Line 5,426 ⟶ 5,845:
takeT=replicate('Take one down, pass it around,', 100)
print, b+wallT+string(10B)+b+wallT2+string(10B)+takeT+string(10B)+b2+wallT+string(10B)
End</
I found the above example very helpful but overdone. This is a more simple version:
<
n_bottles=99
b1 = reverse(SINDGEN(n_bottles,START=1))
Line 5,438 ⟶ 5,857:
takeT=replicate('Take one down, pass it around,', n_bottles)
print, b1+wallT+string(10B)+b1+wallT2+string(10B)+takeT+string(10B)+b2+wallT+string(10B)
End</
=={{header|Idris}}==
<syntaxhighlight lang="idris">
beerSong : Fin 100 -> String
beerSong x = verses x where
Line 5,461 ⟶ 5,880:
verses fZ = ""
verses (fS n) = (verse (fS n)) ++ (verses n)
</syntaxhighlight>
=={{header|Inform 6}}==
<
if(i == 1) return "bottle";
Line 5,483 ⟶ 5,902:
Beer(99);
];
</syntaxhighlight>
=={{header|Inform 7}}==
=== Programmatic solution ===
<
When play begins:
Line 5,496 ⟶ 5,915:
say "Take one down, pass it around[line break]";
say "[N - 1] bottle[s] of beer on the wall[paragraph break]";
end the story.</
=== World model solution ===
This solution uses in-game objects to represent the wall and the bottles.
<
The plural of bottle of beer is bottles of beer. A bottle of beer is a kind of thing.
Line 5,518 ⟶ 5,937:
To say what's on the wall:
if more than one thing is on the wall, say list of things on the wall;
otherwise say "[number of things on the wall in words] bottle[s] of beer".</
=={{header|Io}}==
<
if(i==0, return "no more bottles of beer")
if(i==1, return "1 bottle of beer")
Line 5,536 ⟶ 5,952:
bottles(i - 1), " on the wall.\n\n"
)
)</
=={{header|Intercal}}==
<syntaxhighlight lang="intercal">PLEASE DO ,10 <- #1
PLEASE DO ,10SUB#1 <- #176
PLEASE DO ,11 <- #30
PLEASE DO ,11SUB#1 <- #76
DO ,11SUB#2 <- #190
DO ,11SUB#3 <- #80
DO ,11SUB#4 <- #200
PLEASE DO ,11SUB#5 <- #256
DO ,11SUB#6 <- #248
DO ,11SUB#7 <- #144
DO ,11SUB#8 <- #216
PLEASE DO ,11SUB#9 <- #202
DO ,11SUB#10 <- #14
DO ,11SUB#11 <- #144
DO ,11SUB#12 <- #98
PLEASE DO ,11SUB#13 <- #190
DO ,11SUB#14 <- #160
DO ,11SUB#15 <- #256
DO ,11SUB#16 <- #88
PLEASE DO ,11SUB#17 <- #74
DO ,11SUB#18 <- #14
DO ,11SUB#19 <- #128
DO ,11SUB#20 <- #114
PLEASE DO ,11SUB#21 <- #214
DO ,11SUB#22 <- #24
DO ,11SUB#23 <- #112
DO ,11SUB#24 <- #162
PLEASE DO ,11SUB#25 <- #22
DO ,11SUB#26 <- #104
DO ,11SUB#27 <- #80
DO ,11SUB#28 <- #256
PLEASE DO ,11SUB#29 <- #2
DO ,11SUB#30 <- #228
PLEASE DO ,12 <- #49
PLEASE DO ,12SUB#1 <- #76
DO ,12SUB#2 <- #190
DO ,12SUB#3 <- #80
DO ,12SUB#4 <- #200
PLEASE DO ,12SUB#5 <- #256
DO ,12SUB#6 <- #248
DO ,12SUB#7 <- #144
DO ,12SUB#8 <- #216
PLEASE DO ,12SUB#9 <- #202
DO ,12SUB#10 <- #14
DO ,12SUB#11 <- #144
DO ,12SUB#12 <- #98
PLEASE DO ,12SUB#13 <- #190
DO ,12SUB#14 <- #160
DO ,12SUB#15 <- #256
DO ,12SUB#16 <- #88
PLEASE DO ,12SUB#17 <- #218
DO ,12SUB#18 <- #36
DO ,12SUB#19 <- #38
DO ,12SUB#20 <- #164
PLEASE DO ,12SUB#21 <- #176
DO ,12SUB#22 <- #48
DO ,12SUB#23 <- #162
DO ,12SUB#24 <- #14
PLEASE DO ,12SUB#25 <- #128
DO ,12SUB#26 <- #208
DO ,12SUB#27 <- #162
DO ,12SUB#28 <- #222
PLEASE DO ,12SUB#29 <- #48
DO ,12SUB#30 <- #8
DO ,12SUB#31 <- #120
DO ,12SUB#32 <- #66
PLEASE DO ,12SUB#33 <- #48
DO ,12SUB#34 <- #246
DO ,12SUB#35 <- #136
DO ,12SUB#36 <- #184
PLEASE DO ,12SUB#37 <- #256
DO ,12SUB#38 <- #202
DO ,12SUB#39 <- #110
DO ,12SUB#40 <- #104
PLEASE DO ,12SUB#41 <- #42
DO ,12SUB#42 <- #126
DO ,12SUB#43 <- #56
DO ,12SUB#44 <- #88
PLEASE DO ,12SUB#45 <- #72
DO ,12SUB#46 <- #56
DO ,12SUB#47 <- #80
DO ,12SUB#48 <- #242
PLEASE DO ,12SUB#49 <- #228
PLEASE DO ,13 <- #31
PLEASE DO ,13SUB#1 <- #76
DO ,13SUB#2 <- #190
DO ,13SUB#3 <- #80
DO ,13SUB#4 <- #200
PLEASE DO ,13SUB#5 <- #256
DO ,13SUB#6 <- #248
DO ,13SUB#7 <- #144
DO ,13SUB#8 <- #216
PLEASE DO ,13SUB#9 <- #202
DO ,13SUB#10 <- #14
DO ,13SUB#11 <- #144
DO ,13SUB#12 <- #98
PLEASE DO ,13SUB#13 <- #190
DO ,13SUB#14 <- #160
DO ,13SUB#15 <- #256
DO ,13SUB#16 <- #88
PLEASE DO ,13SUB#17 <- #74
DO ,13SUB#18 <- #14
DO ,13SUB#19 <- #128
DO ,13SUB#20 <- #114
PLEASE DO ,13SUB#21 <- #214
DO ,13SUB#22 <- #24
DO ,13SUB#23 <- #112
DO ,13SUB#24 <- #162
PLEASE DO ,13SUB#25 <- #22
DO ,13SUB#26 <- #104
DO ,13SUB#27 <- #80
DO ,13SUB#28 <- #256
PLEASE DO ,13SUB#29 <- #194
DO ,13SUB#30 <- #36
DO ,13SUB#31 <- #256
PLEASE DO ,20 <- #10
PLEASE DO ,20 SUB #1 <- #76
DO ,20 SUB #2 <- #196
DO ,20 SUB #3 <- #4
DO ,20 SUB #4 <- #132
PLEASE DO ,20 SUB #5 <- #36
DO ,20 SUB #6 <- #164
DO ,20 SUB #7 <- #228
DO ,20 SUB #8 <- #100
PLEASE DO ,20 SUB #9 <- #52
DO ,20 SUB #10 <- #180
PLEASE DO ,21 <- #10 BY #10
PLEASE DO ,21SUB#1#1 <- #248
PLEASE DO ,21SUB#1#2 <- #120
PLEASE DO ,21SUB#1#3 <- #184
PLEASE DO ,21SUB#1#4 <- #56
PLEASE DO ,21SUB#1#5 <- #216
PLEASE DO ,21SUB#1#6 <- #88
PLEASE DO ,21SUB#1#7 <- #152
PLEASE DO ,21SUB#1#8 <- #24
PLEASE DO ,21SUB#1#9 <- #232
PLEASE DO ,21SUB#1#10 <- #104
DO ,21SUB#2#1 <- #128
DO ,21SUB#2#2 <- #256
DO ,21SUB#2#3 <- #64
DO ,21SUB#2#4 <- #192
DO ,21SUB#2#5 <- #96
DO ,21SUB#2#6 <- #224
DO ,21SUB#2#7 <- #32
DO ,21SUB#2#8 <- #160
DO ,21SUB#2#9 <- #112
DO ,21SUB#2#10 <- #240
DO ,21SUB#3#1 <- #64
DO ,21SUB#3#2 <- #192
DO ,21SUB#3#3 <- #256
DO ,21SUB#3#4 <- #128
DO ,21SUB#3#5 <- #32
DO ,21SUB#3#6 <- #160
DO ,21SUB#3#7 <- #224
DO ,21SUB#3#8 <- #96
DO ,21SUB#3#9 <- #48
DO ,21SUB#3#10 <- #176
DO ,21SUB#4#1 <- #192
DO ,21SUB#4#2 <- #64
DO ,21SUB#4#3 <- #128
DO ,21SUB#4#4 <- #256
DO ,21SUB#4#5 <- #160
DO ,21SUB#4#6 <- #32
DO ,21SUB#4#7 <- #96
DO ,21SUB#4#8 <- #224
DO ,21SUB#4#9 <- #176
DO ,21SUB#4#10 <- #48
PLEASE DO ,21SUB#5#1 <- #32
PLEASE DO ,21SUB#5#2 <- #160
PLEASE DO ,21SUB#5#3 <- #224
PLEASE DO ,21SUB#5#4 <- #96
PLEASE DO ,21SUB#5#5 <- #256
PLEASE DO ,21SUB#5#6 <- #128
PLEASE DO ,21SUB#5#7 <- #192
PLEASE DO ,21SUB#5#8 <- #64
PLEASE DO ,21SUB#5#9 <- #16
PLEASE DO ,21SUB#5#10 <- #144
DO ,21SUB#6#1 <- #160
DO ,21SUB#6#2 <- #32
DO ,21SUB#6#3 <- #96
DO ,21SUB#6#4 <- #224
DO ,21SUB#6#5 <- #128
DO ,21SUB#6#6 <- #256
DO ,21SUB#6#7 <- #64
DO ,21SUB#6#8 <- #192
DO ,21SUB#6#9 <- #144
DO ,21SUB#6#10 <- #16
DO ,21SUB#7#1 <- #96
DO ,21SUB#7#2 <- #224
DO ,21SUB#7#3 <- #32
DO ,21SUB#7#4 <- #160
DO ,21SUB#7#5 <- #64
DO ,21SUB#7#6 <- #192
DO ,21SUB#7#7 <- #256
DO ,21SUB#7#8 <- #128
DO ,21SUB#7#9 <- #80
DO ,21SUB#7#10 <- #208
DO ,21SUB#8#1 <- #224
DO ,21SUB#8#2 <- #96
DO ,21SUB#8#3 <- #160
DO ,21SUB#8#4 <- #32
DO ,21SUB#8#5 <- #192
DO ,21SUB#8#6 <- #64
DO ,21SUB#8#7 <- #128
DO ,21SUB#8#8 <- #256
DO ,21SUB#8#9 <- #208
DO ,21SUB#8#10 <- #80
PLEASE DO ,21SUB#9#1 <- #16
PLEASE DO ,21SUB#9#2 <- #144
PLEASE DO ,21SUB#9#3 <- #208
PLEASE DO ,21SUB#9#4 <- #80
PLEASE DO ,21SUB#9#5 <- #240
PLEASE DO ,21SUB#9#6 <- #112
PLEASE DO ,21SUB#9#7 <- #176
PLEASE DO ,21SUB#9#8 <- #48
PLEASE DO ,21SUB#9#9 <- #256
PLEASE DO ,21SUB#9#10 <- #128
DO ,21SUB#10#1 <- #144
DO ,21SUB#10#2 <- #16
DO ,21SUB#10#3 <- #80
DO ,21SUB#10#4 <- #208
DO ,21SUB#10#5 <- #112
DO ,21SUB#10#6 <- #240
DO ,21SUB#10#7 <- #48
DO ,21SUB#10#8 <- #176
DO ,21SUB#10#9 <- #128
DO ,21SUB#10#10 <- #256
PLEASE DO ,22 <- #10
PLEASE DO ,22 SUB #1 <- #8
DO ,22 SUB #2 <- #136
DO ,22 SUB #3 <- #72
DO ,22 SUB #4 <- #200
PLEASE DO ,22 SUB #5 <- #40
DO ,22 SUB #6 <- #168
DO ,22 SUB #7 <- #104
DO ,22 SUB #8 <- #232
PLEASE DO ,22 SUB #9 <- #24
DO ,22 SUB #10 <- #152
DO .10 <- #9
DO .11 <- #9
PLEASE DO ,10 <- #1
PLEASE DO ,10SUB#1 <- #176
DO READ OUT ,10
DO COME FROM (999)
DO (500) NEXT
PLEASE DO ,11SUB#1 <- .5
DO READ OUT ,11
DO (500) NEXT
DO ,12SUB#1 <- .5
PLEASE DO READ OUT ,12
PLEASE DO .6 <- '?"!10~.10'~#1"$#1'~#3
DO (50) NEXT
PLEASE DO .7 <- '?"!11~.11'~#1"$#1'~#3
DO (70) NEXT
DO .2 <- #1
DO .1 <- .11
PLEASE DO (1010) NEXT
DO .11 <- .3
DO (600) NEXT
DO (101) NEXT
(70) DO (71) NEXT
DO .11 <- #9
DO .2 <- #1
PLEASE DO .1 <- .10
DO (1010) NEXT
DO .10 <- .3
DO (600) NEXT
DO (101) NEXT
(71) DO RESUME .7
(50) DO (51) NEXT
PLEASE DO FORGET #1
DO .2 <- #1
DO .1 <- .11
PLEASE DO (1010) NEXT
DO .11 <- .3
DO (600) NEXT
PLEASE DO .7 <- '?"!11~.11'~#1"$#1'~#3
DO (80) NEXT
DO (101) NEXT
(80) DO (81) NEXT
DO GIVE UP
(81) DO RESUME .7
(51) DO RESUME .6
(101) DO FORGET #1
(999) DO FORGET #1
(600) DO (500) NEXT
DO ,13SUB#1 <- .5
DO READ OUT ,13
DO RESUME #1
(500) DO ,30 <- #1
DO .1 <- .10
DO (1020) NEXT
PLEASE DO ,30SUB#1 <- ,20SUB.1
DO READ OUT ,30
DO .3 <- .1
DO .1 <- .11
DO (1020) NEXT
PLEASE DO ,30SUB#1 <- ,21SUB .3 .1
DO READ OUT ,30
DO .5 <- ,22SUB.1
PLEASE DO RESUME #1</syntaxhighlight>
=={{header|Ioke}}==
<
case(i,
0, "no more bottles of beer",
Line 5,549 ⟶ 6,268:
"take one down, pass it around," println
"#{bottle(i - 1)} on the wall.\n" println
)</
=={{header|J}}==
As posted at the [http://www.jsoftware.com/jwiki/Essays/99_Bottles_of_Beer J wiki]
<
bobw=: bob , ' on the wall'"_
beer=: bobw , ', ' , bob , '; take one down and pass it around, ' , bobw@<:
beer"0 >:i.-99</
{{Out}}
Line 5,565 ⟶ 6,284:
2 bottles of beer on the wall, 2 bottles of beer; take one down and pass it around, 1 bottle of beer on the wall
1 bottle of beer on the wall, 1 bottle of beer; take one down and pass it around, 0 bottles of beer on the wall </pre>
=={{header|Jakt}}==
<syntaxhighlight lang="jakt">
fn bottle_string(bottle_count: i64) throws -> String => match bottle_count {
0 => "No more bottles"
1 => "1 bottle"
else => format("{} bottles", bottle_count)
}
fn main() {
mut bottle_count = 99
while bottle_count > 0 {
println("{} of beer on the wall", bottle_string(bottle_count))
println("{} of beer", bottle_string(bottle_count))
println("Take one down, pass it around")
bottle_count--
println("{} of beer on the wall", bottle_string(bottle_count))
if bottle_count > 0 {
println("")
}
}
}
</syntaxhighlight>
=={{header|Janet}}==
<syntaxhighlight lang="janet">
(defn bottles [n]
(match n
0 "No more bottles"
1 "1 bottle"
_ (string n " bottles")))
(loop [i :down [99 0]]
(print
(bottles i) " of beer on the wall\n"
(bottles i) " of beer\nTake one down, pass it around\n"
(bottles (- i 1)) " of beer on the wall\n\n"))
</syntaxhighlight>
=={{header|Java}}==
===Console===
MessageFormat's choice operator is used to properly format plurals.
<
public class Beer {
Line 5,587 ⟶ 6,345:
}
}
}</
'''Optimized for speed and few I/O operations'''
<
public static void main(String[] args) {
int bottles = 99;
Line 5,603 ⟶ 6,361:
System.out.println(sb.append(verse3));
}
}</
'''Recursive'''
<
public static void main(String args[]) {
song(99);
Line 5,622 ⟶ 6,380:
}
}
}</
=== An object-oriented solution ===
Line 5,633 ⟶ 6,391:
{{libheader|AWT}}
This version requires user interaction. The first two lines are shown in a text area on a window. The third line is shown on a button which you need to click to see the fourth line in a message box. The numbers update and the process repeats until "0 bottles of beer on the wall" is shown in a message box, when the program ends.
<
import java.awt.event.ActionEvent;
import javax.swing.JButton;
Line 5,673 ⟶ 6,431:
}
}
}</
=={{header|JavaScript}}==
===ES3-5===
<
while (beer > 0) {
var verse = [
Line 5,690 ⟶ 6,448:
beer--;
}
</syntaxhighlight>
===ES6===
<
while (beer > 0) {
let verse = `${beer} bottles of beer on the wall,
Line 5,702 ⟶ 6,460:
console.log(verse);
beer--;
}</
===Functional / Recursive===
<
var songTemplate = "{X} bottles of beer on the wall \n" +
"{X} bottles of beer \n"+
Line 5,715 ⟶ 6,473:
}
console.log(song(bottles, songTemplate));</
===Other Examples===
Line 5,721 ⟶ 6,479:
Comment: This being a "one-liner" is arguable. The author has chosen not to put a line break after the declaration of the <code>beer</code> variable. By using the authors definition, most of the other solutions could pass as a "one-liner".
<
var beer; while ((beer = typeof beer === "undefined" ? 99 : beer) > 0) document.write( beer + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall<br>" + beer + " bottle" + (beer != 1 ? "s" : "") + " of beer<br>Take one down, pass it around<br>" + (--beer) + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall<br>" );</
Legitimate "one-liner" with grammar check, using declarative methods.
<
Object Oriented
<
this.count = count || 99;
}
Line 5,754 ⟶ 6,512:
var bar = new Bottles(99);
bar.sing();</
An alternative version:
<
if (!isFinite(Number(n)) || n == 0) n = 100;
var a = '%% bottles of beer',
Line 5,775 ⟶ 6,533:
}
window.onload = bottleSong;</
=={{header|Joy}}==
<
_beerlib == true
HIDE
beer == "of beer " putchars
wall == "on the wall" putchars
take1 == "Take one down and pass it around, " putchars
dup3 == dup dup dup
comma == ", " putchars
period ==
bottles == [
[
[put "bottles " putchars] ifte
sing-verse == dup3 bottles beer wall comma
bottles beer ".\n" putchars
take1
sing-verse-0 == "No more bottles of beer on the wall, no more bottles of beer\n" putchars
"Go to the store and buy some more, " putchars
99 bottles pop beer wall period newline
IN
Line 5,803 ⟶ 6,561:
sing-verses == [null]
[sing-verse-0]
[sing-verse
END.
99 sing-verses.</syntaxhighlight>
=={{header|jq}}==
'''Minimalist:'''
<
| (. - range(0;.+1) )
| "
Line 5,813 ⟶ 6,574:
\(.) bottles of beer
Take one down, pass it around
\(.) bottles of beer on the wall"</
{{out}}
<
...
Line 5,831 ⟶ 6,592:
0 bottles of beer
Take one down, pass it around
0 bottles of beer on the wall</
'''Variant''':
<
def s: if . == 1 then "" else "s" end;
def bottles:
Line 5,847 ⟶ 6,608:
;
$bottles | tonumber | sing</
{{out}}
<
...
2 bottles of beer on the wall
Line 5,864 ⟶ 6,625:
No more bottles of beer
Take one down, pass it around
No more bottles of beer on the wall.</
=={{header|Jsish}}==
<
function plural(n:number):string { return (bottles == 1) ? "" : "s"; }
function no(n:number):string { return (bottles == 0) ? "No" : n.toString(); }
Line 5,878 ⟶ 6,639:
bottles--;
printf("%s bottle%s of beer on the wall\n\n", no(bottles), plural(bottles));
} while (bottles > 0);</
=={{header|Julia}}==
'''one-liner'''
<
another solution, handling grammar cases "No more bottles", "1 bottle", "<n> bottles"
<
n==1 ? "1 bottle" :
"$n bottles"
Line 5,895 ⟶ 6,656:
$(bottles(n-1)) of beer on the wall
""")
end</
shorter, but more cryptic, version of the previous `bottles` function
<
=={{header|K}}==
<
=={{header|Kabap}}==
<syntaxhighlight lang="kabap">
// Loop that spits lyrics to "99 Bottles of Beer"
Line 5,916 ⟶ 6,677:
return = $out;
</syntaxhighlight>
=={{header|Kitten}}==
<
define bottles_of_beer_on_the_wall (Int32 -> +IO):
Line 5,951 ⟶ 6,712:
"one bottle"
else:
n show " bottles" cat</
=={{header|Klingphix}}==
<syntaxhighlight lang="text">include ..\Utilitys.tlhy
:bottles
Line 5,976 ⟶ 6,737:
drop] for
" " input</
=={{header|Klong}}==
<
itone::{:[x=1;"it";"one"]}
numno::{:[x=0;"no";x]}
Line 5,997 ⟶ 6,758:
.d(bottles(x-1));
.p(" of beer on the wall");.p("")}
drink'1+|!99</
=={{header|Kotlin}}==
<
for (i in 99.downTo(1)) {
println("$i bottles of beer on the wall")
Line 6,007 ⟶ 6,768:
}
println("No more bottles of beer on the wall!")
}</
=={{header|LabVIEW}}==
Line 6,015 ⟶ 6,776:
The signature file:
<
type println string -> o.
type round int -> o.
type bottles_song int -> o.
</syntaxhighlight>
The module file:
<
println Str :- print Str, print "\n".
Line 6,045 ⟶ 6,806:
M is N - 1,
bottles_song M.
</syntaxhighlight>
Then we produce the desired output by setting the system to solve for this goal:
<syntaxhighlight lang="lambda
=={{header|Lambdatalk}}==
<
{def beer
{lambda {:i}
Line 6,086 ⟶ 6,847:
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}}==
<
: verses(*)
dup " bottles of beer on the wall\n" ~ .
Line 6,097 ⟶ 6,877:
;
99 iota 1 + reverse verses</
=={{header|Lasso}}==
Line 6,103 ⟶ 6,883:
=== Simple loop ===
<
beer = 99,
song = ''
Line 6,117 ⟶ 6,897:
}
#song</
=== Query Expression ===
<
#beer + ' bottles of beer on the wall' +
#beer + ' bottles of beer\n' +
'Take one down, pass it around\n' +
--#beer + ' bottles of beer on the wall\n'
)->join('\n')</
=== Query Expression with Autocollect ===
<
local(s = 's')
Line 6,141 ⟶ 6,921:
'Take one down, pass it around,<br>'
#n + ' bottle' + #s + ' of beer on the wall.<br><br>'
^}</
=={{header|LaTeX}}==
===Recursive===
<
\newcounter{beer}
\newcommand{\verses}[1]{
Line 6,161 ⟶ 6,941:
\begin{document}
\verses{99}
\end{document}</
===Iterative===
Line 6,167 ⟶ 6,947:
Just for fun, this version uses Roman numerals.
<
\newcounter{beer}
\newcounter{showC}
Line 6,186 ⟶ 6,966:
\begin{document}
\verses{99}
\end{document}</
===References===
Line 6,192 ⟶ 6,972:
=={{header|LDPL}}==
<
DATA:
bottles-in-the-wall is number
Line 6,221 ⟶ 7,001:
end if
repeat
</syntaxhighlight>
=={{header|Lhogho}}==
<
if :i = 0 [output "|No more bottles of beer|]
if :i = 1 [output "|One bottle of beer|]
Line 6,256 ⟶ 7,036:
;Using it:
sing 99</
=={{header|Limbo}}==
<syntaxhighlight lang="limbo">
implement Beer;
Line 6,286 ⟶ 7,066:
}
</syntaxhighlight>
=={{header|Lingo}}==
<
put i & " bottles of beer on the wall"
put i & " bottles of beer"
Line 6,306 ⟶ 7,086:
put "No more bottles of beer"
put "Go to the store and buy some more"
put "99 bottles of beer on the wall"</
=={{header|Lisp}}==
Line 6,315 ⟶ 7,095:
=={{header|Logo}}==
<
if :n = 0 [output [No more bottles]]
if :n = 1 [output [1 bottle]]
Line 6,326 ⟶ 7,106:
print sentence bottles :n-1 [of beer on the wall]
end
for [n 99 1] [verse :n (print)]</
=={{header|Logtalk}}==
<
:- initialization(sing(99)).
Line 6,351 ⟶ 7,131:
write(N), write(' bottles').
:- end_object.</
=={{header|LOLCODE}}==
Line 6,357 ⟶ 7,137:
=={{header|Lua}}==
<
local function plural (bottles) if bottles == 1 then return '' end return 's' end
Line 6,367 ⟶ 7,147:
print (bottles..' bottle'..plural(bottles)..' of beer on the wall')
print ()
end</
With a numeric for-loop and string formatting:
<
%i bottle%s of beer
Take one down, pass it around
Line 6,380 ⟶ 7,160:
for i = 99, 1, -1 do
print(verse:format(i, suffix(i), i, suffix(i), i-1, suffix(i-1)))
end</
Using Lua relational operators and multiple return values:
<
local s = i == 1 and "1 bottle of beer" or
i == 0 and "no more bottles of beer" or
Line 6,394 ⟶ 7,174:
print( string.format("%s on the wall,\n%s,\ntake one down, pass it around,", bottles(i)),
string.format("\n%s on the wall.\n", bottles(i-1)) )
end</
=={{header|Lucid}}==
<
// The print out is a list of lines. So the output is not separated by new lines, rather
// by '[' and ']' -- I cant figure out how to do string concatenation with numbers in lucid.
Line 6,409 ⟶ 7,189:
beer(A) = if A > 0 then A else `No more' fi;
bottle(A) = if A eq 1 then `bottle of beer' else `bottles of beer' fi;
end</
=={{header|NATURAL}}==
El código es de Chris Bednara
<
LOCAL
01 #BOTTLES (I2)
Line 6,444 ⟶ 7,224:
WRITE 'TAKE ONE DOWN, PASS IT AROUND'
*
END</
=={{header|M4}}==
<
define(`BOTTLE', `bottle of beer')dnl
define(`WALL', `on the wall')dnl
Line 6,456 ⟶ 7,236:
ifelse(`$1',`0',,`TAKE')
ifelse(`$1',`0',,`NINETEEN(eval($1-1))')')dnl
NINETEEN(99)</
=={{header|MACRO-11}}==
<syntaxhighlight lang="macro-11">
;
; 99 BOTTLES OF BEER
Line 6,606 ⟶ 7,386:
.END START</
=={{header|MAD}}==
<
BOTLES = 99
Line 6,650 ⟶ 7,430:
VECTOR VALUES NOMORE = $35HNO MORE BOTTLES OF BEER ON THE WALL*$
VECTOR VALUES EMPTY = $*$
END OF PROGRAM</
=={{header|make}}==
Line 6,656 ⟶ 7,436:
{{libheader|jot}}
{{works with|BSD make}}
<
UP != jot - 2 `expr $(START) - 1` 1
Line 6,682 ⟶ 7,462:
@echo $(START) bottles of beer on the wall,
@echo $(START) bottles of beer.
@echo Take one down, pass it around.</
Usage: <tt>make</tt> or <tt>make START=99</tt>
Line 6,688 ⟶ 7,468:
=== GNU make ===
{{works with|GNU make|3.81}}
<
1-bottles: 1-beer pass
Line 6,704 ⟶ 7,484:
pass:
@echo "Take one down and pass it around,"</
Usage: <tt>make 99-bottles</tt>
Line 6,713 ⟶ 7,493:
===== Without using a shell command to decrement the counter =====
{{works with|GNU make|3.81}}
<
numbers:=$(foreach x,$(filter-out 0,$(digits)),$(foreach y,$(digits),$x$y))
numbers+=$(digits)
Line 6,766 ⟶ 7,546:
@echo "$(most) $(bottles) $(beer) $(wall)!"
@echo ""
</syntaxhighlight>
Usage: <tt>make</tt> or <tt>make N-bottles</tt> or <tt>make N</tt>
Line 6,775 ⟶ 7,555:
'''Long version''' (a real loop version made by Hisashi Iizawa)''':'''
<
S(bt<%@#!7~|4{y1xv.us+rp(om%lj"ig}fd"cx``uz]rwvYnslkTonPfOjiKgJeG]\EC_X]@[Z<R;VU7S6QP2N1LK-I
,GF(D'BA#?>7~;:9y16w43s10)p-,l*#(i&%e#d!~``{tyxZpuXsrTTongOkdMhg`Hd]ba`_^W@[ZYXW9UNSRQPOHMLK
Line 7,020 ⟶ 7,800:
'qLQn"2~YK-hBG)ccC<NM]K7}|Y{i1U/Ad2sO/LoJIkZFEhf$TA!~>+{]]88Y6XslT0B.zl,=<;(J%d]F!`}BW@yyY+d
tO8Mq5PINkjih-BTecQCa`qp>J~5XzW165eR,bO/L^m8[6j'D%UBdc>}`N^9x&vonF2qCSRmf>M*;J&8^]\n~}}@?[xY
+:Pt8S6o]3l~Y..,,*@RQ</
'''Short version''' (a just printing out the lyrics version made by Johannes E. Schindelin)''':'''
<
R5nO2~L/JzHe@ED'`N$?\7<;:W87C54us1N`.-nm*GF43gU#dRx=_N)sK&vo4Vrqji.z,Odvh'&e7Fb"
DlkAVhZS+Q9(7M_$o"110EhzgxFccbBNqLo\}}Y9z7gT4us1*/LKn87G(!&VeT/c?w|_M(xwY5XmVTjo
Line 7,120 ⟶ 7,900:
RQPO1GFEDh+A@dDCBA@98\65Y9y1Uv.-,+*N.-,%Ij(!~}C#zyxw=^zsrqp6nm3qpoQmlkd*Ka`&G]\[
Z~^]\UyYX:VOs6qQJIm0k.DhHG)?cCBA#98\<|432V65.-Q+*No-&%I)('g}Cdzyxw=^zyxq7on4rTji
h.ledcba'_^$o</
=={{header|Maple}}==
<
i, `if`( i<>1, "bottles", "bottle" ),
i, `if`( i<>1, "bottles", "bottle" ),
i-1, `if`( i-1<>1, "bottles", "bottle") ),
i = 99..1, -1 );</
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
BottleSong[n_] := Speak[
Line 7,139 ⟶ 7,919:
]
BottleSong /@ Range[99,1,-1]</
=={{header|MATLAB}}==
<
disp( [ sprintf(['%d bottles of beer on the wall, %d bottles of beer.\n'...
Line 7,152 ⟶ 7,932:
%beer...like college.
end</
=={{header|Maxima}}==
<
printf(true, "~d bottle~p of beer on the wall~%", i, i),
printf(true, "~d bottle~p of beer~%", i, i),
Line 7,180 ⟶ 7,960:
0 bottles of beer on the wall
*/</
=={{header|MAXScript}}==
<
resetMaxFile #noPrompt
viewport.setType #view_top
Line 7,208 ⟶ 7,988:
redrawViews()
sleep delay
)</
=== A one-line version ===
Since MAXscript is an expression based language (everything returns a value), it is relatively easy to write long expressions that are only one line long. the following single-line snippet (broken for clarity on the webpage) produces a grammatically correct printout of the song.
<
(if i == 1 then " bottle" else " bottles") + " of beer\nTake one down, pass it around\n" + (i - 1) as string + (if i - 1 == 1 then "\
bottle" else " bottles") + " of beer on the wall\n" + (if i - 1 == 0 then "\nno more beer" else "")))</
=={{header|MEL}}==
<syntaxhighlight lang="mel">// Rosetta Code problem: https://rosettacode.org/wiki/99_bottles_of_beer
// by Jjuanhdez, 10/2022
string $temp0[] , $temp1[] , $text0 , $text1;
string $theGrp = `group -em`;
for ($i = 99 ; $i > -1 ; $i--)
{
$text0 = string($i) + " bottles of beer on the wall, " + string($i) +" bottles of beer.";
$text1 = "Take one down and pass it around, " + string($i-1) +" bottles of beer on the wall.";
if ($i == 1)
{
$text0 = string($i) + " bottle of beer on the wall, " + string($i) +" bottle of beer.";
$text1 = "Take one down and pass it around, no more bottles of beer on the wall.";
}
if ($i == 0)
{
$text0 = "No more bottles of beer on the wall, no more bottles of beer. ";
$text1 = "Go to the store and buy some more, 99 bottles of beer on the wall.";
}
$temp0 = `textCurves -ch 0 -f "Times New Roman|h-13|w400|c0" -t ($text0)`;
$temp1 = `textCurves -ch 0 -f "Times New Roman|h-13|w400|c0" -t ($text1)`;
setAttr ($temp0[0] + ".ty") (($i * 8) + 3);
setAttr ($temp1[0] + ".ty") ($i * 8);
parent $temp0[0] $theGrp ;
parent $temp1[0] $theGrp ;
}</syntaxhighlight>
=={{header|Mercury}}==
<syntaxhighlight lang="mercury">
% file: beer.m
% author:
Line 7,279 ⟶ 8,087:
string.format("%d bottles of beer", [i(N)])
).
</syntaxhighlight>
=={{header|min}}==
{{works with|min|0.19.3}}
<
(
Line 7,294 ⟶ 8,102:
) :verse
99 'verse over times</
=={{header|MiniScript}}==
Going for the simple/obvious solution here...
<
if n == 0 then return "no bottles"
if n == 1 then return "1 bottle"
Line 7,314 ⟶ 8,122:
for i in range(99, 1)
verse i
end for</
{{out}}
<pre>99 bottles of beer on the wall
Line 7,339 ⟶ 8,147:
=={{header|MIPS Assembly}}==
<
##################################
# 99 bottles of beer on the wall #
Line 7,417 ⟶ 8,225:
li $v0,10
syscall
</syntaxhighlight>
=={{header|Mirah}}==
<
99.downto(1) do |i|
puts "#{i} bottle#{plural} of beer on the wall,"
Line 7,433 ⟶ 8,241:
end
end
</syntaxhighlight>
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = map (Stdout . verse) [99, 98 .. 1]
verse :: num->[char]
verse n = lay [bottles n ++ " of beer on the wall,",
bottles n ++ " of beer,",
"Take " ++ pronoun ++ " down and pass it around,",
bottles (n-1) ++ " of beer on the wall!",
[]]
where pronoun = "it", if n=1
= "one", otherwise
bottles :: num->[char]
bottles n = "No more bottles", if n=0
= "1 bottle", if n=1
= (show n) ++ " bottles", otherwise</syntaxhighlight>
=={{header|mIRC Scripting Language}}==
<
while (%x) {
echo -ag %x bottles of beer on the wall
Line 7,443 ⟶ 8,269:
dec %x
echo -ag %x bottles of beer on the wall
}</
=={{header|ML/I}}==
=== Simple iterative version ===
<
"" 99 bottles - simple iterative version
MCSKIP MT,<>
Line 7,466 ⟶ 8,292:
>
"" Do it
BOTTLES 99</
=== Recursive version ===
<
"" 99 bottles - recursive version
MCSKIP MT,<>
Line 7,488 ⟶ 8,314:
>
"" Do it
BOTTLES 99</
Line 7,511 ⟶ 8,337:
Internal macros define English word replacements for decimal numbers from 0 to 99.
<syntaxhighlight lang="ml/i">
MCSKIP - WITH - NL
-- The line above defines the comment syntax: -- through to newline is completely deleted.
Line 7,610 ⟶ 8,436:
-- Sing 7 flasks of Armagnac on the table: Take a swig, throw it down!
-- Emilie vists, she brings some more.
</syntaxhighlight>
=== Usage: ===
Line 7,617 ⟶ 8,443:
=== Output: ===
<syntaxhighlight lang="ml/i">
Ninety nine bottles of beer on the wall,
Ninety nine bottles of beer.
Line 7,641 ⟶ 8,467:
Ninety nine bottles of beer on the wall!
</syntaxhighlight>
=={{header|mLite}}==
<
fun itone 1 = "it"
Line 7,667 ⟶ 8,493:
;
bottles ` ston ` default (argv 0, "99")</
Allows for number of bottles to be specified on command line with the default being 99, viz
<pre>mlite -f 99bob.m 2</pre>
Line 7,687 ⟶ 8,513:
=={{header|Modula-2}}==
<
IMPORT InOut;
Line 7,709 ⟶ 8,535:
InOut.WriteLn
UNTIL nr = 0
END b99.</
=={{header|Modula-3}}==
<
IMPORT IO, Fmt;
Line 7,724 ⟶ 8,550:
IO.Put("\n");
END;
END Bottles.</
=={{header|Monkey}}==
Tic's every one and a half seconds and sings(text's) the song out.
<
Import mojo
Line 7,805 ⟶ 8,631:
End
</syntaxhighlight>
=={{header|MontiLang}}==
<
WHILE i
Line 7,818 ⟶ 8,642:
i 1 - VAR i .
ENDWHILE</
Another way to solve the task that shows some more features of the language.
<
def rima
Line 7,838 ⟶ 8,662:
|No more| rima
|Press ENTER to end | INPUT clear</
Infinite loop
<
def rima /# n -- n #/
Line 7,865 ⟶ 8,689:
botellas out | bottles of beer on the wall.| print
|Press ENTER to continue | INPUT clear
endwhile</
=={{header|MOO}}==
<
while (bottles > 0)
unit = (bottles == 1 ? "bottle" | "bottles");
Line 7,876 ⟶ 8,700:
bottles = bottles - 1;
endwhile
player:tell("0 bottles of beer on the wall.");</
=={{header|MoonScript}}==
<
i != 1 and 's' or ''
Line 7,891 ⟶ 8,715:
i < 4 and (p b) or (p b-1),
i%3 == 1 and ' on the wall' or ''
io.write '\n'</
=={{header|MUMPS}}==
===Recursive===
<
Write !!,n," bottle",$Select(n=1:"",1:"s")," of beer on the wall."
Write !,n," bottle",$Select(n=1:"",1:"s")," of beer."
Line 7,902 ⟶ 8,726:
Quit
Do beer(99)</
===Iterative===
<
Write !!,n," bottle",$Select(n=1:"",1:"s")," of beer on the wall."
Write !,n," bottle",$Select(n=1:"",1:"s")," of beer."
Line 7,911 ⟶ 8,735:
Quit
For ii=99:-1:0 Do beer(ii)</
===Brain-damaging===
<
set template1="i_n_""of beer on the wall. ""_i_n_"" of beer. """
set template2="""Take""_n2_""down, pass it around. """
Line 7,925 ⟶ 8,749:
repeat
write "One more time!",! hang 5
goto bottles</
=={{header|MyDef}}==
Line 7,931 ⟶ 8,755:
<div>
mydef_page -mgeneral bottles.def
</div>
It outputs bottles.txt, which contains the lyrics.
<
$(for:i in 99-1)
$(i) bottles of beer on the wall
Line 7,942 ⟶ 8,766:
$(i) bottles of beer on the wall
NEWLINE
</syntaxhighlight>
=={{header|N/t/roff}}==
Line 7,950 ⟶ 8,774:
{{works with|All TROFF}}
<
.de L1
.ie \\n(BS>1 \{ \
Line 7,967 ⟶ 8,791:
.nf
.L1
.fi</
===New version (compatible only with GNU TROFF)===
Line 7,973 ⟶ 8,797:
{{works with|GNU TROFF|1.22.2}}
<
.nf
.while \n[beers]>0 \{ \
Line 7,987 ⟶ 8,811:
\n-[beers] bottles of beer on the wall.
\} \" while \n[beers]>0
.fi</
=={{header|Nanoquery}}==
{{trans|Ursa}}
<
// 99 bottles of beer
//
Line 8,013 ⟶ 8,837:
println "1 bottle of beer on the wall.\n"
end if
end for</
=={{header|NASL}}==
<
repeat {
display(bottles, ' bottles of beer on the wall\n');
Line 8,022 ⟶ 8,846:
display('Take one down, pass it around\n');
display(--bottles, ' bottles of beer on the wall\n\n');
} until bottles < 1;</
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
<doc>
<h3>Rosetta Code, 99 bottles of beer on the wall, in Neko</h3>
Line 8,055 ⟶ 8,879:
$print(nonesome(beers), plural(beers), message);
if (beers > 0) $print("\n");
}</
{{out}}
Line 8,072 ⟶ 8,896:
=={{header|Nemerle}}==
<
using System.Console;
Line 8,095 ⟶ 8,919:
Sing(i)
}
}</
=={{header|NetRexx}}==
<
beer = "bottles of beer on the wall"
removeOne = "Take one down, pass it arround,"
Line 8,118 ⟶ 8,942:
say removeOne
say "No more" beer
</syntaxhighlight>
=={{header|newLISP}}==
Line 8,124 ⟶ 8,948:
=={{header|Nial}}==
<
0=, 'No more bottles of beer' first,
1=, 'One bottle of beer' first,
Line 8,136 ⟶ 8,960:
]
bottles is iterate (write verse) reverse count</
=={{header|Night}}==
<
if(x == 1) {
print("1 bottle of beer on the wall,\n");
Line 8,157 ⟶ 8,981:
}
}
bottles(1);</
This code ''should'' work according to the docs, but due to a few bugs in the current implementation it doesn't.
=={{header|Nim}}==
<
case n
of 0:
Line 8,177 ⟶ 9,001:
echo "No more bottles of beer on the wall, no more bottles of beer."
echo "Go to the store and buy some more, 99 bottles of beer on the wall."</
other:
<
for i in countdown(99, 1):
Line 8,201 ⟶ 9,025:
No more bottles of beer on the wall""", i)
else:
discard</
compact:
<
proc pluralize(a: int): string =
Line 8,215 ⟶ 9,039:
$1 bottle$3 of beer
Take one down, pass it around
$2 bottle$4 of beer on the wall""", i, i-1, pluralize(i), pluralize(i-1))</
organized:
<
var verse = """$1 bottle$3 of beer on the wall
Line 8,231 ⟶ 9,055:
for i in countdown(99, 1):
echo format(verse, i, i-1, pluralize(i), pluralize(i-1))</
=={{header|Nix}}==
<
let
bottle = x: "${toString x} bottle${if (x == 1) then "" else "s"} of beer";
Line 8,245 ⟶ 9,069:
${beer { x = x - 1; }}'';
in
beer { }</
=={{header|NS-HUBASIC}}==
With grammatical support for "1 bottle of beer"
<
20 FOR BOTTLES=99 TO 1 STEP -1
30 BOTTLES$=" BOTTLES OF BEER"
Line 8,259 ⟶ 9,083:
90 IF BOTTLES-1=0 THEN BOTTLE$=" BOTTLES OF BEER"
100 PRINT BOTTLES-1 BOTTLES$ WALL$
110 NEXT</
Without grammatical support for "1 bottle of beer"
<
20 WALL$=" ON THE WALL"
30 FOR BOTTLES=99 TO 1 STEP -1
Line 8,269 ⟶ 9,093:
60 PRINT "TAKE ONE DOWN, PASS IT AROUND"
70 PRINT BOTTLES-1 BOTTLES$ WALL$
80 NEXT</
=={{header|Nutt}}==
<syntaxhighlight lang="Nutt">
module main imports native.io.output.say
for i|->{1,2..99;<|>) do
say(""+i+" bottles of beer on the wall, "+i+" bottles of beer")
say("Take one down and pass it around, "+(i-1)+" bottles of beer on the wall.")
done
end
</syntaxhighlight>
=={{header|OASYS}}==
<
class player {}
Line 8,303 ⟶ 9,139:
print "Type 'beer' for beer.\nType 'quit' to quit.\n"
}
</syntaxhighlight>
=={{header|OASYS Assembler}}==
Line 8,309 ⟶ 9,145:
=={{header|Oberon-2}}==
<
IMPORT Out;
Line 8,332 ⟶ 9,168:
Out.Ln
UNTIL nr = 0
END b99.</
=={{header|Objeck}}==
<
class Bottles {
function : Main(args : String[]) ~ Nil {
Line 8,347 ⟶ 9,183:
} while(bottles > 0);
}
}</
=={{header|Objective-C}}==
<
int main()
Line 8,366 ⟶ 9,202:
}
return 0;
}</
=={{header|OCaml}}==
===For-loop===
<
Printf.printf "%d bottles of beer on the wall\n" n;
Printf.printf "%d bottles of beer\n" n;
Printf.printf "Take one down, pass it around\n";
Printf.printf "%d bottles of beer on the wall\n\n" (pred n);
done</
===Recursive===
Recursive version that handles plurals.
<
let
line2 = function
Line 8,404 ⟶ 9,240:
if n > 1 then beer (n-1);;
beer 99;;</
===Monadic===
Monadic version, expressing actions which evolve the program state and log output. Special cases and grammar rules are handled.
<
module Writer = struct
type 'a t = 'a * string
Line 8,434 ⟶ 9,270:
| n -> take n >>= summary |> verse)
let sing start =
Writer.(emit (verse (return start)))</
Output for initial beer-count of two:
<syntaxhighlight lang="text"># sing 2;;
2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.
Line 8,448 ⟶ 9,284:
Go to the store and buy some more, 99 bottles of beer on the wall.
- : int = 99</
Note the output value is 99... reflecting the state at termination.
=={{header|Octave}}==
<
bottle = "bottle";
ofbeer = "of beer";
Line 8,475 ⟶ 9,311:
endfunction
bottles(99);</
=={{header|Odin}}==
<syntaxhighlight lang="odin">package main
import "core:fmt"
printf :: fmt.printf //Give fn on right an arbitrary name, or 9x fmt.printf("...")
bob :: proc( n: int , x: int){
for i := x; i > 0 ; i -=1 {
if n >= 2 do printf("%d bottles of beer",n)
else if n == 1 do printf("1 bottle of beer")
else if n == 0 do printf("No more bottles of beer")
if i == 1 do printf(".\n")
if i > 1 do printf(" on the wall.\n")
if i > 2 do printf("\n")
}
}
main :: proc(){
n := 99
bob(n, 2)
for i := n - 1 ; i >= 0 ; i -= 1 {
printf("Take one down; pass it around.\n")
bob(i, 3)
}
printf ("Go to the store and buy some more.\n")
printf ("%i bottles of beer on the wall.\n",n)
}
</syntaxhighlight>
=={{header|Oforth}}==
<
"bottles of beer\nTake one down, pass it around\n" const: T
#[ 100 swap - dup . B print dup . T print 1- . B .cr ] 99 each </
=={{header|Ol}}==
Line 8,489 ⟶ 9,354:
=={{header|Onyx}}==
<
dup cvs ` bottle' cat exch 1 ne {`s' cat} if
` of beer' cat
Line 8,504 ⟶ 9,369:
} def
99 -1 1 {WriteStanza} for</
Output:
Line 8,522 ⟶ 9,387:
=={{header|OOC}}==
<
sing_line: func (b: Int, suffix: Bool) {
"#{b > 0 ? "#{b}" : "No more"} bottle#{b == 1 ? "" : "s"}" print()
Line 8,547 ⟶ 9,412:
}
}
</syntaxhighlight>
=={{header|ooRexx}}==
Line 8,553 ⟶ 9,418:
=={{header|OpenEdge/Progress}}==
<
&GLOBAL-DEFINE bbm bottles of beer
&GLOBAL-DEFINE bbs bottle of beer
Line 8,585 ⟶ 9,450:
END.
RETURN 0.
END FUNCTION.</
=={{header|Openscad}}==
El código es de Marc Vanlindt (marc@vanlindt.be)
<
s1 = " of beer";
s2 = " on the wall";
Line 8,607 ⟶ 9,472:
beer(n = n-1);
}
}</
=={{header|Order}}==
Line 8,614 ⟶ 9,479:
==="Pure" Order===
This solution uses only Order language constructs to generate and manipulate tokens:
<
ORDER_PP
Line 8,630 ⟶ 9,495:
(take one down, pass it around,) 8space
8ap(8B, 8dec(8N)) (of beer on the wall.))),
100, 1)))</
===C Preprocessor===
...but since most of the logic is simple substitution, it makes more sense (and is significantly more efficient) to make the C Preprocessor do most of the work without the help of the Order interpreter. This version shows how to integrate normal C Preprocessor macros into an Order program:
<
#define GEN_phrase(N_bottles, N_minus_1_bottles) \
Line 8,657 ⟶ 9,522:
100, 1))
#undef GEN_phrase</
Either example could obviously also form the core of a C solution (demonstrating the intended use of Order).
=={{header|Oxygene}}==
<
namespace ConsoleApplication2;
Line 8,697 ⟶ 9,562:
end.
</syntaxhighlight>
=={{header|Oz}}==
=== Constraint Programming ===
Note: In real life, you would never solve a simple iterative task like this with constraint programming. This is just for fun.
<
%% describe the possible solutions of the beer 'puzzle'
proc {BeerDescription Solution}
Line 8,726 ⟶ 9,591:
%% show all solutions to the 'puzzle'
{ForAll {SearchAll BeerDescription}
System.showInfo}</
=== Iterative ===
<
fun {Bottles N}
if N == 1 then "1 bottle"
Line 8,742 ⟶ 9,607:
"Take one down, pass it around\n"#
{Bottles I-1}#" of beer on the wall\n"}
end</
=={{header|PARI/GP}}==
<
print(n" bottles of beer on the wall");
print(n" bottles of beer");
Line 8,752 ⟶ 9,617:
);
print("2 bottles of beer on the wall\n2 bottles of beer\nTake one down, pass it around\n1 bottle of beer on the wall\n");
print("1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around\nNo more bottles of beer on the wall")</
=={{header|Pascal}}==
See [[99 Bottles of Beer/Pascal]]
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
begin
for var i:=99 to 1 step -1 do
begin
Println(i,'bottles of beer on the wall');
Println(i,'bottles of beer');
Println('Take one down, pass it around');
Println(i-1,'bottles of beer on the wall');
Println
end;
end.</syntaxhighlight>
=={{header|Perl}}==
<
my $verse = <<"VERSE";
Line 8,775 ⟶ 9,653:
print $verse;
redo unless $done;
}</
Alternatively:
<
{
$bottles = sprintf("%s bottle%s of beer on the wall\n",(($n==0)?"No":$n), (($n==1)?"":"s"));
print( (($n==99)?"":"$bottles\n") .
(($n==0)?"":(substr(${bottles}x2,0,-12) . "\nTake one down, pass it around\n")) );
}</
Correct grammar and nice spacing in modern perl:
<
$num = 99;
Line 8,799 ⟶ 9,677:
say "No more bottles of beer on the wall, no more bottles of beer.";
say "Go to the store and buy some more, 99 bottles of beer on the wall.";</
Using perl5 as a DSL factory leveraging $_'s global nature:
<
#!/usr/bin/env perl
use strict;
Line 8,818 ⟶ 9,696:
, take
, bottles, qq{\n\n}
} for reverse 0..99;</
=={{header|Phix}}==
<!--<
<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>
Line 8,852 ⟶ 9,730:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</
=={{header|Phixmonti}}==
<
dup if
dup 1 == if
Line 8,875 ⟶ 9,753:
99 1 -1 3 tolist
for verse . endfor</
With syntactic sugar
<
def bottles
Line 8,897 ⟶ 9,775:
1 - bottles print " on the wall." ? nl
drop
endfor</
=={{header|PHL}}==
Line 8,903 ⟶ 9,781:
{{trans|C}}
<
extern printf;
Line 8,917 ⟶ 9,795:
} while(bottles > 0);
return 0;
]</
=={{header|PHP}}==
<
$plural = 's';
foreach (range(99, 1) as $i) {
Line 8,934 ⟶ 9,812:
echo "No more bottles of beer on the wall!\n";
}
?></
===shorter way===
<
foreach(range(99,1) as $i) {
$p = ($i>1)?"s":"";
Line 8,949 ⟶ 9,827:
}
echo "No more Bottles of beer on the wall";
?></
===Tag syntax===
<
<?=$i?> bottle<?=$i==1 ? '' : 's'?> of beer on the wall,
<?=$i?> bottle<?=$i==1 ? '' : 's'?> of beer!
Line 8,962 ⟶ 9,840:
No more bottles of beer on the wall!
<?php endif?>
<?php endforeach?></
===modifing way===
<
$verse = <<<VERSE
100 bottles of beer on the wall,
Line 8,982 ⟶ 9,860:
echo $verse;
}
?></
===ultra compact alternative===
supports grammar and has no leading and trailing new lines or spaces.
Also one does not have to close the <?php tag, it is even recommended not to close it, if closing it is not necessary
<
for($i=100;$i>0;$i--){
$p2=$i." bottle".(($i>1)?"s":"")." of beer";
Line 8,993 ⟶ 9,871:
$p3="Take one down, pass it around\n";
echo (($i<100)?$p1."\n":"").$p1.$p2."\n".$p3.(($i<2)?($i-1).substr($p1,1,28):"");
}</
===gettext alternative===
supports grammar and translations.
<
$bottles = 99;
Line 9,013 ⟶ 9,891:
}
}
printf('No more bottles of beer on the wall'); //No more bottles of beer on the wall</
===Using printf===
Fun with HEREDOC and printf placeholders
<
$lyrics = <<<ENDVERSE
Line 9,033 ⟶ 9,911:
printf( $lyrics, $x != 1 ? 's' : '', $x--, $x != 1 ? 's' : '', $x > 0 ? $x : 'No more' );
}
</syntaxhighlight>
{{Out}}
Line 9,086 ⟶ 9,964:
=={{header|Picat}}==
<syntaxhighlight lang="picat">
beer1(N) =>
Beer = N,
Line 9,112 ⟶ 9,990:
cond(B > 0, (B-1).to_string() ++ BT ++ BW ++ NL, ""),
S = S1.
</syntaxhighlight>
=={{header|PicoLisp}}==
See [[99 Bottles of Beer/Lisp]]
=={{header|Piet}}==
Line 9,118 ⟶ 9,999:
=={{header|Pike}}==
<
for(int i = 99; i > 0; i--){
write(i + " bottles of beer on the wall, " + i + " bottles of beer.\n");
Line 9,125 ⟶ 10,006:
write("No more bottles of beer on the wall, no more bottles of beer.\n");
write("Go to the store and buy some more, 99 bottles of beer on the wall.\n");
}</
alternate version:
<
void main()
Line 9,151 ⟶ 10,032:
string song = bottles * "take one down, pass it around,\n";
write(song);
}</
=={{header|PILOT}}==
El código es de Akira KIDA (SDI00379@niftyserve.or.jp)
<
U : *beers
Line 9,172 ⟶ 10,053:
C(bottles = 1) :$T = 1 bottle
C(bottles > 1) :$T = #bottles bottles
E :</
=={{header|PIR}}==
{{works with|Parrot|Tested with 2.4.0}}
<
.param int b
if b == 1 goto ONE
Line 9,207 ⟶ 10,088:
DRUNK:
end
.end</
=={{header|Plain English}}==
<syntaxhighlight lang="text">
To run:
Start up.
Sing 99 of bottles of beer on the wall.
Wait for the escape key.
Shut down.
To sing a number of bottles of beer on the wall:
Put the number into a counter.
Loop.
Write the first line given the counter.
Write the second line given the counter.
Write "Take one down, pass it around" to the console.
Subtract 1 from the counter.
Write the first line given the counter.
If the counter is 0, break.
Write "" on the console.
Repeat.
To write the first line given a counter:
If the counter is 0, write "No more bottles of beer on the wall" to the console; exit.
If the counter is 1, write "1 bottle of beer on the wall" to the console; exit.
Write the counter then " bottles of beer on the wall" to the console.
To write the second line given a counter:
If the counter is 1, write "1 bottle of beer" to the console; exit.
Write the counter then " bottles of beer" to the console.
</syntaxhighlight>
=={{header|PlainTeX}}==
<
\def\beers{
\par\ifbeer>0 \the\bottles~\else No more \fi
Line 9,232 ⟶ 10,143:
\ifnum\number\bottles>0\repeat
\bye</
=={{header|PL/I}}==
<
nBottles: procedure(n);
declare n fixed;
Line 9,272 ⟶ 10,183:
put skip;
end;
end bottles;</
=={{header|PL/M}}==
<
BDOS: PROCEDURE(F,PARAM); /* CALL CP/M BDOS */
Line 9,343 ⟶ 10,254:
CALL BDOS(BDOS$EXIT,0);
EOF</
=={{header|Pointless}}==
<
-- Print the lyrics to the song '99 bottles of beer'
Line 9,375 ⟶ 10,286:
showBottle(n) =
format("{} {}", [n, bottleStr])
where bottleStr = if n == 1 then "bottle" else "bottles"</
=={{header|Pony}}==
=== Recursive ===
<
let _env: Env
new create(env: Env) =>
Line 9,398 ⟶ 10,309:
end
bottles(n-1)
end</
=== Iterative ===
<
let _env: Env
new create(env: Env) =>
Line 9,417 ⟶ 10,328:
end
n = n - 1
until n < 0 end</
=={{header|Pop11}}==
<
while n > 0 do
printf(n, '%p bottles of beer on the wall\n');
Line 9,430 ⟶ 10,341:
enddefine;
bootles(99);</
=={{header|PostScript}}==
<syntaxhighlight lang="postscript">%!PS
/Helvetica findfont 9 scalefont setfont
Line 9,469 ⟶ 10,380:
song
showpage
%%EOF</
=={{header|Potion}}==
Line 9,475 ⟶ 10,386:
No extra credit.
<
verse = (n) :
(n, " bottles of beer on the wall\n"
Line 9,485 ⟶ 10,396:
verse(i) join print
"\n" print
.</
=={{header|PowerShell}}==
Line 9,494 ⟶ 10,405:
Immediately prints all output to the console.
<
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");
}</
'''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.
<
void setup() {
size(200, 140);
Line 9,521 ⟶ 10,432:
i = max(i-1, 1); // stop decreasing at 1-0 bottles
}
</syntaxhighlight>
==={{header|Processing Python mode}}===
{{trans|Processing}}
<
def setup():
size(200, 140)
Line 9,544 ⟶ 10,455:
def next():
global i
i = max(i - 1, 1) # stop decreasing at 1-0 bottles</
==={{header|Processing.R}}===
'''Console output'''
<
stdout$print(bottlesong(99))
}
Line 9,564 ⟶ 10,475:
}
return(verses)
}</
=={{header|ProDOS}}==
Line 9,574 ⟶ 10,485:
=={{header|Python}}==
===One line===
{{Works with|Python|3.
<syntaxhighlight lang="python">
for i in range(99, 0, -1):b='bottles of beer';w=f' {b} on the wall';print(f'{i}{w}, {i} {b}\nTake one down and pass it around, {i-1}{w}.\n')
</syntaxhighlight>
===Pythonic version===
{{Works with|Python|3}}
<syntaxhighlight lang="python">
VERSE = '''\
{n} bottle{s} of beer on the wall
{n} bottle{s} of beer
Take one down
{n_minus_1} bottle{s2} of beer on the wall
'''
for n in range(99, 0, -1):
if n == 1:
n_minus_1 = 'No more'
s = ''
s2 = 's'
elif n == 2:
n_minus_1 = n - 1;
s = 's'
s2 = ''
else:
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+}}
<
Line 9,752 ⟶ 10,637:
if __name__ == '__main__':
main()</
===Functional, pythonic version===
Line 9,760 ⟶ 10,645:
Inspired by [[99_Bottles_of_Beer#Functional|Functional version]]
<
99 Bottles of Beer on the Wall made functional
Line 9,888 ⟶ 10,773:
if __name__ == '__main__':
print(beer_song())
</syntaxhighlight>
{{Out}}
Line 9,920 ⟶ 10,805:
Inspired by the [[99_Bottles_of_Beer#Python_3.2C_functional.2C_pythonic_version|Functional Pythonic Version]]
<
Excercise of style. An overkill for the task :-D
Line 10,176 ⟶ 11,061:
__all__ = (Song.__name__, MuchItemsSomewhere.__name__, muchBeersOnTheWall.__name__, balladOfProgrammer.__name__)
</syntaxhighlight>
=== Other solutions ===
Line 10,182 ⟶ 11,067:
=={{header|Q}}==
<
-1 bobw each reverse 1 + til 99</
=={{header|QB64}}==
Line 10,189 ⟶ 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.]]
----
<
CONST BottleSpeed = 3
PLAY "<"
Line 10,300 ⟶ 11,185:
_MAPTRIANGLE (0, 0)-(w - 1, 0)-(w - 1, h - 1), Image TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
END SUB
</syntaxhighlight>
=={{header|Qore}}==
Line 10,306 ⟶ 11,191:
===Simple Solution===
<
%enable-all-warnings
Line 10,315 ⟶ 11,200:
printf("take one down, pass it around\n");
printf("%d bottles of beer on the wall\n", $i);
}</
===Concurrent (Unordered) Solution===
<
%enable-all-warnings
Line 10,346 ⟶ 11,231:
}
$count.waitForZero();</
=={{header|Quackery}}==
<
[ stack ] is bottles ( --> [ )
Line 10,384 ⟶ 11,269:
say 'The song "99 Bottles of Beer on the Wall":' cr cr
99 song echo$
</syntaxhighlight>
=={{header|Quill}}==
<
(count > 0) if {
new_count := count - 1;
Line 10,401 ⟶ 11,286:
}
};
99 bottles</
=={{header|Quite BASIC}}==
With grammatical support for "1 bottle of beer"
<
20 for n=99 to 1 step -1
30 let b=" bottles of beer"
Line 10,415 ⟶ 11,300:
90 if n-1=0 then let b=" bottles of beer"
100 print n-1;b;w
110 next n</
Without grammatical support for "1 bottle of beer"
<
20 let w=" on the wall"
30 for n=99 to 1 step -1
Line 10,425 ⟶ 11,310:
60 print "Take one down, pass it around"
70 print n-1;b;w
80 next n</
=={{header|R}}==
===Simple looping solution===
<
song = function(bottles){
Line 10,445 ⟶ 11,330:
}
song(99)#play the song by calling the function</
===Vector solutions===
<
cat(paste(99:1,ifelse((99:1)!=1," bottles"," bottle")," of beer on the wall\n",99:1,ifelse((99:1)!=1," bottles"," bottle")," of beer\n","Take one down, pass it around\n",98:0,ifelse((98:0)!=1," bottles"," bottle")," of beer on the wall\n\n",sep=""),sep="")
Line 10,455 ⟶ 11,340:
#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)) </
=={{header|Ra}}==
<syntaxhighlight lang="ra">
class BottlesOfBeer
**Prints the "99 Bottles of Beer" song"**
Line 10,508 ⟶ 11,393:
if bottle = 1, return "1 bottle"
return "[bottle] bottles"
</syntaxhighlight>
=={{header|Racket}}==
<
#lang racket
(define (sing bottles)
Line 10,520 ⟶ 11,405:
(unless (= 1 bottles) (sing (sub1 bottles))))
(sing 99)
</syntaxhighlight>
=={{header|Raku}}==
Line 10,527 ⟶ 11,412:
=== A Simple Way ===
<syntaxhighlight lang="raku"
repeat while --$b {
Line 10,539 ⟶ 11,424:
sub b($b) {
"$b bottle{'s' if $b != 1} of beer";
}</
=== A Clearer Way ===
Line 10,545 ⟶ 11,430:
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"
sing $bottles, :wall;
sing $bottles;
Line 10,562 ⟶ 11,447:
my $location = $wall ?? " on the wall" !! "";
say "$quantity bottle$plural of beer$location"
}</
=== A More Extravagant Way ===
{{works with|Rakudo|2015.09}}
<syntaxhighlight lang="raku"
my @bottles = flat 'bottles' xx 98, 'bottle', 'bottles' xx 2;
my @actions = flat 'Take one down, pass it around' xx 99,
Line 10,579 ⟶ 11,464:
say $c;
say "$d $e of beer on the wall\n";
}</
=={{header|RapidQ}}==
<syntaxhighlight lang="rapidq">
dim nBott as integer
nBott = 99
Line 10,596 ⟶ 11,481:
while inkey$="":wend
end
</syntaxhighlight>
=={{header|Rascal}}==
<
module demo::basic::Bottles
Line 10,616 ⟶ 11,501:
println("Go to the store and buy some more, 99 bottles of beer on the wall.");
}
</syntaxhighlight>
=={{header|Raven}}==
<
$i 1 = if
"bottle" as $b
Line 10,631 ⟶ 11,516:
else
$i 1 - "%d bottles" format
"%s of beer on the wall.\n\n" print</
{{out}}
Last couple of stanzas are:
Line 10,650 ⟶ 11,535:
=={{header|REBOL}}==
<
Title: "99 Bottles of Beer"
URL: http://rosettacode.org/wiki/99_Bottles_of_Beer
Line 10,668 ⟶ 11,553:
"Take one down, pass it around" crlf
bottles n - 1 "of beer on the wall" crlf
]]</
Output ''(selected highlights)'':
Line 10,687 ⟶ 11,572:
This one prints with proper grammar. "Bottles" changed to "bottle" at the end of the 2 line, and throughout the 1 line. 0 changed to "No" in the last line:
<
x: rejoin [
i b: " bottles of beer" o: " on the wall. " i b
Line 10,695 ⟶ 11,580:
switch i [1 [r x j k r at x 10 j k r x "0" "No"] 2 [r at x 40 j k]]
print x
] halt</
Here's a simple 1 line console version:
<
=={{header|Red}}==
<
Title: "99 Bottles of Beer"
Original-Author: oofoe
Line 10,722 ⟶ 11,607:
"Take one down, pass it around" crlf
bottles n - 1 "of beer on the wall" crlf
]]</
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <Verses 99>>;
};
Verses {
'-'1 = ;
s.1 = <Verse s.1>
<Verses <- s.1 1>>;
};
Verse {
s.1 = <Bottles s.1> ' of beer on the wall,\n'
<Bottles s.1> ' of beer,\n'
<ThirdLine s.1> '\n'
<Bottles <- s.1 1>> ' of beer on the wall!\n\n';
};
Bottles {
'-'1 = '99 bottles';
0 = 'No more bottles';
1 = '1 bottle';
s.1 = s.1 'bottles';
};
ThirdLine {
0 = 'Go to the store and buy some more,';
1 = 'Take it down and pass it around,';
s.1 = 'Take one down and pass it around,';
};</syntaxhighlight>
=={{header|Relation}}==
<syntaxhighlight lang="relation">
program beer(n)
if n>1
Line 10,748 ⟶ 11,664:
set i = i-1
end while
</syntaxhighlight>
=={{header|Retro}}==
This is based on the [[Forth]] example.
<
Display the text for the *99 Bottles of Beer* song.
Line 10,780 ⟶ 11,696:
#99 verses
~~~</
=={{header|REXX}}==
Complete with a PSA (<u>P</u>ublic <u>S</u>ervice <u>A</u>nnouncement) comment.
<
parse arg N .; if N=='' | N=="," then N=99 /*allow number of bottles be specified.*/
/* [↓] downward count of beer bottles.*/
Line 10,803 ⟶ 11,719:
exit /*we're all done, and also sloshed !. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
s: if arg(1)=1 then return ''; return 's' /*simple pluralizer for gooder English.*/</
{{out|output|text= Below is the first and last three verses of the song:}}
<pre>
Line 10,843 ⟶ 11,759:
=={{header|Ring}}==
This is a simple solution
<
switch i
on 0
Line 10,864 ⟶ 11,780:
"
off
next</
{{out}}
<pre>
Line 10,890 ⟶ 11,806:
Rockstar solution without special cases for the last 2 verses.
<
Problems are " bottles of beer"
Carol says Take one down, pass it around
Line 10,900 ⟶ 11,816:
Knock the beers down
Say it with Love
</syntaxhighlight>
=={{header|RPG}}==
Line 10,906 ⟶ 11,822:
{{works with|RPGIII|}}
<
F********************************************************************
F*
Line 10,996 ⟶ 11,912:
O 15 'Pass it around'
O E 1 SKIPLN
</syntaxhighlight>
=={{header|RPL}}==
≪ " bottles" " of beer" " on the wall" "Take one down and pass it around,"
→ n b of on take
≪ n 1 '''FOR''' j
j →STR b + of + DUP on + "," + 1 DISP
"," + 2 DISP
take 3 DISP
j 1 ≠ LAST - →STR "No more" IFTE
b +
'''IF''' j 2 == '''THEN''' 1 OVER SIZE 1 - SUB '''END'''
of + on + "." + 4 DISP
-1 '''STEP'''
≫ ≫ '<span style="color:blue">BOB</span>' STO
99 <span style="color:blue">BOB</span>
=={{header|RPL/2}}==
===Simple solution===
<
<<
99 do
Line 11,021 ⟶ 11,952:
<<
" bottle" + over if 1 <> then "s" + end " of beer" +
>></
===Recursive and multithreaded solution===
<
<<
// Child process is started.
Line 11,066 ⟶ 11,997:
RECURSIVE
end
>></
=={{header|Ruby}}==
<
99.downto(1) do |i|
puts "#{i} bottle#{plural} of beer on the wall,"
Line 11,081 ⟶ 12,012:
puts "No more bottles of beer on the wall!"
end
end</
Ruby has variable traces, so we can do
<
$bottles = %Q{#{val == 0 ? 'No more' : val.to_s} bottle#{val == 1 ? '' : 's'}}
end
Line 11,095 ⟶ 12,026:
puts "#{$bottles} of beer on the wall"
puts ""
end</
or...
<
puts "#{of_beer} bottle#{ending} of beer on the wall,"
puts "#{of_beer} bottle#{ending} of beer"
Line 11,111 ⟶ 12,042:
puts "No more bottles of beer on the wall!"
end
end</
or...
<
"#{beer>0 ? beer : "no more"} bottle#{"s" if beer!=1} of beer#{" on the wall" if wall}"
end
Line 11,126 ⟶ 12,057:
end
puts ", #{bottles(remaining-1,true)}.\n\n"
end</
===Simple solution===
<
99.downto(1) do |bottles|
puts "#{bottles} bottle#{"s" if bottles != 1} of beer on the wall.",
Line 11,136 ⟶ 12,067:
"#{bottles - 1} bottle#{"s" if bottles - 1 != 1} of beer on the wall.\n\n"
end
</syntaxhighlight>
=={{header|Rust}}==
===Simple Solution===
<
for n in (0..100).rev() {
match n {
Line 11,158 ⟶ 12,089:
}
}
}</
===Using a trait and impl===
<
fn bottles_of_beer(&self) -> Self;
fn on_the_wall(&self);
Line 11,189 ⟶ 12,120:
println!("-----------------------------------");
}
}</
=={{header|S-BASIC}}==
<
rem - print lyrics to "99 Bottles of Beer on the Wall"
Line 11,236 ⟶ 12,167:
end
</syntaxhighlight>
=={{header|Sather}}==
<
main is
s :STR;
Line 11,252 ⟶ 12,183:
end;
end;
end;</
=={{header|Scala}}==
Line 11,259 ⟶ 12,190:
=={{header|Scheme}}==
<
(define (sing)
(define (sing-to-x n)
Line 11,272 ⟶ 12,203:
(display "would you wanna me to sing it again?")))
(sing-to-x 99))
</syntaxhighlight>
=={{header|Scratch}}==
Line 11,278 ⟶ 12,209:
=={{header|sed}}==
<
h
: b
Line 11,303 ⟶ 12,234:
y/0123456789/9012345678/
h
bb</
=={{header|Seed7}}==
<
const proc: main is func
Line 11,324 ⟶ 12,255:
writeln("No more bottles of beer on the wall, no more bottles of beer.");
writeln("Go to the store and buy some more, 99 bottles of beer on the wall.")
end func;</
=={{header|SenseTalk}}==
Below is a straightforward implementation in SenseTalk. A completely fanciful version (which also works!) can be found here: http://www.99-bottles-of-beer.net/language-sensetalk-1794.html
<
set bottleCount to 99
set bottleCount's format to "Words"
Line 11,343 ⟶ 12,274:
put empty
end repeat
</syntaxhighlight>
Output:
<
Ninety-Nine bottles of beer on the wall,
Ninety-Nine bottles of beer!
Line 11,367 ⟶ 12,298:
Take one down and pass it around,
Zero bottles of beer on the wall!
</syntaxhighlight>
=={{header|SequenceL}}==
<
import <Utilities/Sequence.sl>;
Line 11,399 ⟶ 12,330:
plural := "s" when num /= 1 else "";
in
count ++ " bottle" ++ plural ++ " of beer";</
=={{header|Set lang}}==
<
set s 32
set m 44
Line 11,498 ⟶ 12,429:
set k 1
set ? 9
> EOF</
=={{header|Shen}}==
See [[99 Bottles of Beer/Lisp]]
=={{header|Shiny}}==
<
s: if i > 1 's' end
Line 11,514 ⟶ 12,448:
say "Take one down, pass it around!"
end
say "Aww...no more bottles of beer on the wall... it must be your shout :)"</
=={{header|Sidef}}==
<
var bottles = "#{i == 0 ? 'No' : i} bottle#{i == 1 ? '' : 's'}"
var sentence = "#{bottles} of beer on the wall" -> say
Line 11,524 ⟶ 12,458:
say "Take one down, pass it around\n"
}
}</
'''Simpler:'''
<
say "#{n} bottles of beer on the wall, #{n} bottles of beer!"
say "Take one down, pass it around, #{n - 1} bottle#{n > 2 ? 's' : ''} of beer on the wall.\n"
Line 11,533 ⟶ 12,467:
say "One bottle of beer on the wall, one bottle of beer!"
say "Take one down, pass it around, no more bottles of beer on the wall."</
=={{header|Simula}}==
<
COMMENT AUTHOR: TIM GOODWIN ;
COMMENT DATE: 04/20/05 ;
Line 11,572 ⟶ 12,506:
BEER(99);
END;
</syntaxhighlight>
'''Simpler:'''
<
author: Jack Leunissen
date: 03/10/07;
Line 11,603 ⟶ 12,537:
OUTIMAGE;
END;
</syntaxhighlight>
=={{header|SkookumScript}}==
<
99.to 1
[
Line 11,615 ⟶ 12,549:
"Take one down, pass it around\n"
bottles(idx-1) " of beer on the wall\n")
]</
=={{header|Slate}}==
<
[| nprinted |
nprinted: n printString ; ' bottle' ; (n > 1 ifTrue: ['s'] ifFalse: ['']) ; ' of beer'.
Line 11,632 ⟶ 12,566:
].
99 bottles.</
=={{header|Slope}}==
<
;; 99 bottles of beer
;;
Line 11,658 ⟶ 12,592:
;; main
(bottles-of-beer 99)
</syntaxhighlight>
=={{header|Smalltalk}}==
A straightforward approach:
<
sr := Dictionary new.
sr at: 0 put: ' bottle' ;
Line 11,676 ⟶ 12,610:
Transcript show: (sr at:s) ; show: (sr at:2) ; cr.
(v ~~ 0) ifTrue: [ Transcript show: (sr at:4) ; cr. ].
].</
This version uses Squeak Smalltalk's String >> format: method. and SequencableCollection >> atPin: method
<syntaxhighlight lang="smalltalk">
|bottles plurals |
Transcript clear.
bottles:='{1} bottle{2} of beer on the wall
{1} bottle{2} of beer
Take one down, pass it around
{3} bottle{4} of beer on the wall'.
plurals := #('' 's').
99 to: 1 by: -1 do:[:v |
Transcript show: (bottles format: {(v asString) . (plurals atPin:v) . ((v -1) asString). (plurals atPin:v) }); cr; cr].
Transcript show: 'hic!'; cr.
</syntaxhighlight>
This version uses Squeak Smalltalk's String >> asPluralBasedOn: method to handle the plural and singular cases.
<syntaxhighlight lang="smalltalk">
| bottles |
Transcript clear.
bottles := '{1} {2} of beer on the wall
{1} {2} of beer
Take one down, pass it around
{3} {4} of beer on the wall'.
99 to: 1 by: -1 do: [:i |
Transcript
show: (bottles format: {
i. 'bottle' asPluralBasedOn: i.
i - 1. 'bottle' asPluralBasedOn: i - 1});
cr; cr].
Transcript show: 'hic!'; cr.
</syntaxhighlight>
=={{header|SmileBASIC}}==
Pretty comical version. MML tunes based on QB64 version.
<
IF N==-1 THEN
RETURN "99"
Line 11,728 ⟶ 12,698:
PRINT NUM(I-1);BTL(I-1);" of beer on the wall."
WAITPLAY 131
NEXT</
=={{header|SNOBOL4}}==
<
again output = X " bottles of beer on the wall"
output = X " bottles of beer" ?eq(X,0) :s(zero)
Line 11,738 ⟶ 12,708:
zero output = "Go to store, get some more"
output = "99 bottles of beer on the wall"
end</
===Function===
Line 11,744 ⟶ 12,714:
{{works with|CSnobol}}
Function version with string composition. Function returns one verse for x bottles. Correctly handles bottle/bottles.
<
nl = char(13) char(10) ;* Win/DOS, change as needed
s2 = ' of beer'; s3 = ' on the wall'
Line 11,760 ⟶ 12,730:
n = 2
loop bottles(n); n = gt(n,0) n - 1 :s(loop)
end</
Output:
Line 11,780 ⟶ 12,750:
=={{header|SNUSP}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "bottles" );
pragma annotate( description, "In this puzzle, write code to print out the entire '99 bottles of beer" );
pragma annotate( description, "on the wall' song. A common interview test from Rosetta Code for" );
pragma annotate( description, "testing basic programming skills." );
pragma annotate( author, "Ken O. Burtch" );
pragma license( unrestricted );
pragma restriction( no_external_commands );
procedure Bottles is
begin
for X in reverse 1..99 loop
? strings.image( X ) & " bottles of beer on the wall";
? strings.image( X ) & " bottles of beer";
? "Take one down, pass it around";
? strings.image( integer(X-1) ) & " bottles of beer on the wall" @ "";
end loop;
end Bottles;</syntaxhighlight>
=={{header|Sparkling}}==
<
do {
Line 11,792 ⟶ 12,784:
} while(bottles > 1);
printf("1 bottle of beer on the wall\n1 bottle of beer\nTake it down, pass it around\n0 bottles of beer on the wall\n");</
=={{header|SQL}}==
<syntaxhighlight lang="sql">
select
( 100 - level ) || ' bottle' || case when level != 99 then 's' end || ' of beer on the wall'
Line 11,806 ⟶ 12,798:
|| ( 99 - level ) || ' bottle' || case when level != 98 then 's' end || ' of beer on the wall'
from dual connect by level <= 99;
</syntaxhighlight>
<syntaxhighlight lang="sql">
Line 11,840 ⟶ 12,832:
call bottles_( @bottles, @song);
select @song;
</syntaxhighlight>
This Statement does also work with T-SQL, but only up to 32 beers
<syntaxhighlight lang="sql">
CREATE PROCEDURE bottles
@bottle_count int,
Line 11,892 ⟶ 12,884:
EXECUTE bottles 31, '';
</syntaxhighlight>
<syntaxhighlight lang="sql">
/*These statements work in PostgreSQL (tested in 9.4)*/
Line 11,930 ⟶ 12,922:
ORDER BY n DESC;
</syntaxhighlight>
=={{header|Squirrel}}==
<
function rec(bottles)
{
Line 11,949 ⟶ 12,941:
rec(99);
</syntaxhighlight>
=={{header|Standard ML}}==
<
| bottles x = ( print (Int.toString x ^ " bottles of beer on the wall\n");
print (Int.toString x ^ " bottles of beer\n");
Line 11,958 ⟶ 12,950:
print (Int.toString (x-1) ^ " bottles of beer on the wall\n");
bottles (x-1)
)</
The following code outputs the [https://99-bottles-of-beer.net/lyrics.html full lyrics], generating duplicate text blocks only once.
<
(str o Char.toUpper o String.sub) (s, 0) ^ String.extract (s, 1, NONE)
Line 11,989 ⟶ 12,981:
end
val () = (print o String.concatWith "\n" o unfoldN) (100, verse, clauses 99)</
=={{header|Stata}}==
<
local s s
forvalues i=`1'(-1)0 {
Line 12,033 ⟶ 13,025:
No more bottles of beer
Go to the store and buy some more
2 bottles of beer on the wall...</
=={{header|Suneido}}==
<
while (i > 0)
{
Line 12,047 ⟶ 13,039:
else
Print(i $ ' bottles of beer on the wall\n')
}</
=={{header|SuperCollider}}==
<
(
(99..0).do { |n|
Line 12,069 ⟶ 13,061:
}
)
</syntaxhighlight>
=={{header|SuperTalk}}==
<syntaxhighlight lang="supertalk">-- Rosetta Code problem: https://rosettacode.org/wiki/99_bottles_of_beer
-- by Jjuanhdez, 10/2022
on mouseup
put 99 into numBeerz
put "s it" into modifier
repeat with x = numBeerz down to 1
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,
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}}==
<
for i in (1...99).reversed() {
print("\(i) bottles of beer on the wall, \(i) bottles of beer.")
Line 12,122 ⟶ 13,105:
print("Take one down and pass it around, \(next) bottles of beer on the wall.")
}
</syntaxhighlight>
=={{header|Symsyn}}==
<
BBW : ' Bottles of beer on the wall '
TOD : 'Take one down and pass it around '
Line 12,146 ⟶ 13,129:
goif | go back to if
endif
</syntaxhighlight>
=={{header|Tailspin}}==
<
templates sayBottleCount
when <=1> do
Line 12,166 ⟶ 13,149:
' -> !OUT::write
</syntaxhighlight>
{{out}}
<pre>
Line 12,195 ⟶ 13,178:
=={{header|TIScript}}==
<
var beer = 99;
while (beer > 0)
Line 12,204 ⟶ 13,187:
stdout.printf( "%d bottles of beer on the wall\n", --beer );
}
</syntaxhighlight>
=={{header|TMG}}==
Unix TMG:
<
line1: beer = { 1 < on the wall, > 1 <.> * };
line2: beer = { <If one of those bottles should happen to fall, > 1 < on the wall.> * };
Line 12,214 ⟶ 13,197:
rest: ( [n>=1?] decimal(n) | = { <no more> } );
plural: ( [n!=1?] = { <s> } | = { } );
n: 143;</
=={{header|TorqueScript}}==
<syntaxhighlight lang="torquescript">
for(%i = 99; %i >= 0; %i--)
{
Line 12,225 ⟶ 13,208:
echo(%n SPC (%i == 1 ? "bottle" : "bottles") SPC "of beer on the wall.");
}
</syntaxhighlight>
=={{header|Transd}}==
<syntaxhighlight lang="Scheme">#lang transd
class MaterialAssets: {
what: (λ (textout quantity " " contents " ")),
consume: (λ (-= quantity 1)),
thereIs: (λ (ret quantity)),
quantity: Int(),
contents: String(),
@init: (λ _q Int(0) _c String()
(= quantity _q) (= contents _c))
}
class Storage: {
where: (λ (textout container)),
container: String(),
@init: (λ _c String() (= container _c))
}
class Activity: {
do: (λ (textout action) (consume stuff)),
provideStuff: (λ _s MaterialAssets() (rebind stuff _s)),
action: String(),
@init: (λ _a String() (= action _a)),
stuff: MaterialAssets()
}
class PartyMaker: {
letsRock: (λ
(while (thereIs stuff)
(what stuff) (where box) (lout "")
(what stuff) (lout "")
(do fun) (lout "")
(what stuff) (where box) (lout "\n"))
(lout "OK! What about one more?")
),
stuff: MaterialAssets(),
box: Storage(),
fun: Activity(),
@init: (λ _s MaterialAssets() _b Storage() _f Activity()
(rebind stuff _s) (rebind box _b) (rebind fun _f)
(provideStuff fun stuff))
}
MainModule: {
_start: (λ
locals: party PartyMaker(
MaterialAssets(99 "bottles of beer")
Storage("on the wall")
Activity("Take one down, pass it around"))
(letsRock party)
)
}</syntaxhighlight>
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
LOOP bottle=1,100
Line 12,244 ⟶ 13,282:
PRINT "Take one down, pass it around"
ENDLOOP
</syntaxhighlight>
=={{header|TXR}}==
Line 12,250 ⟶ 13,288:
The <code>(range 99 -1 -1)</code> expression produces a lazy list of integers from 99 down to -1. The <code>mapcar*</code> function lazily maps these numbers to strings, and the rest of the code treats this lazy list as text stream to process, extracting the numbers with some pattern matching cases and interpolating them into the song's text. Functional programming with lazy semantics meets text processing, pattern matching and here documents.
<
@(collect)
@number
Line 12,281 ⟶ 13,319:
@ (end)
@ (end)
@(end)</
To make the song repeat indefinitely, change the first line to:
<
Now it's processing an infinite lazy lists consisting of
Line 12,291 ⟶ 13,329:
=={{header|TypeScript}}==
<
function nbottles(howMany:number){
return `${howMany?howMany:'no'} bottle${howMany!=1?'s':''}`;
Line 12,308 ⟶ 13,346:
}
console.log(beerSong());</
=={{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 12,344 ⟶ 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."</
And a more structured version.
<syntaxhighlight lang="text">for n=99 to 2 step -1
print n;" bottles of beer on the wall, ";n;" bottles of beer!"
print "Take one down, pass it around, ";n-1;" bottle";
Line 12,356 ⟶ 13,394:
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."</
=={{header|UNIX Shell}}==
Line 12,368 ⟶ 13,406:
=={{header|Ursa}}==
<syntaxhighlight lang="text">
#
# 99 bottles of beer
Line 12,393 ⟶ 13,431:
end if
end for
</syntaxhighlight>
=={{header|Ursala}}==
<
# each function takes a natural number to a block of text
Line 12,422 ⟶ 13,460:
#show+
main = whole_song 99</
=={{header|Uxntal}}==
<syntaxhighlight lang="Uxntal">( uxncli 99bottles.rom )
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
|0100 ( -> )
#63 &loop
DUP <print-verse>
[ LIT2 0a -Console/write ] DEO
#01 EQUk ?&done
POP #01 SUB
!&loop
&done BRK
@<print-verse> ( num -- )
DUP <print-bottle> ;dict/wall <print-string>
DUP <print-bottle> [ LIT2 0a -Console/write ] DEO
;dict/take <print-string>
#01 SUB <print-bottle> ;dict/wall !<print-string>
@<print-bottle> ( num -- )
DUP #00 EQU ?&zero
DUP #01 EQU ?&one
<print-dec> ;dict/bottle <print-string>
[ LIT2 "s -Console/write ] DEO
!&end
&one ( num -- )
<print-dec> ;dict/bottle <print-string>
!&end
&zero ( num -- )
POP ;dict/no-more <print-string>
;dict/bottle <print-string>
[ LIT2 "s -Console/write ] DEO
( >> )
&end
;dict/of-beer
( >> )
@<print-string> ( str -- )
&loop
LDAk .Console/write DEO
INC2 LDAk ?&loop
POP2 JMP2r
@<print-dec> ( byte -- )
DUP #64 DIV <print-num>/try
DUP #0a DIV <print-num>/try
( >> )
@<print-num> ( num -- )
#0a DIVk MUL SUB
[ LIT "0 ] ADD .Console/write DEO
JMP2r
&try ( num -- )
DUP ?<print-num>
POP JMP2r
@dict &no-more "No 20 "more $1
&bottle 20 "bottle $1
&of-beer 20 "of 20 "beer 20 $1
&wall "on 20 "the 20 "wall 0a $1
&take "Take 20 "one 20 "down, 20 "pass 20 "it 20 "around 0a $1</syntaxhighlight>
=={{header|UTFool}}==
<syntaxhighlight lang="utfool">
···
http://rosettacode.org/wiki/99_Bottles_of_Beer
Line 12,444 ⟶ 13,547:
s⦂ String: many > 1 ? "s" ! ""
return "⸨many⸩ bottle⸨s⸩ of beer"
</syntaxhighlight>
=={{header|
<
[newline '' puts].
[beer
Line 12,458 ⟶ 13,561:
tailrec].
99 bottles</
=={{header|Vala}}==
<
uint bottles = 99;
do {
Line 12,479 ⟶ 13,582:
print(" of beer on the wall!\n\n");
} while (bottles != 0);
}</
=={{header|VBA}}==
Line 12,490 ⟶ 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.
<
RS(2, " bottles of beer")
RS(3, " on the wall")
Line 12,504 ⟶ 13,607:
} while (#1)
Return</
=={{header|Verbexx}}==
<
@LOOP init:{@VAR n = 99} until:(n == 0)
Line 12,516 ⟶ 13,619:
@SAY "Take one down, pass it around" ;
@SAY n (@fb n) "of beer on the wall\n" ;
};</
=={{header|Verilog}}==
<syntaxhighlight lang="verilog">
module beer;
integer i;
Line 12,538 ⟶ 13,641:
end
endmodule
</syntaxhighlight>
Line 12,546 ⟶ 13,649:
=={{header|Viua VM assembly}}==
<
.function: bottles_of_beer_text/1
.name: %iota number_of_bottles
Line 12,655 ⟶ 13,758:
.end
</syntaxhighlight>
=={{header|V (Vlang)}}==
Fails the task definition for more song, includes the no beer verse.
<
module main
Line 12,695 ⟶ 13,798:
println("")
}
}</
=={{header|Vox}}==
<
// translated from <http://rosettacode.org/wiki/99_Bottles_of_Beer#JavaScript>
Line 12,712 ⟶ 13,815:
(beer != 1 ? "s" : "") + " of beer on the wall\n"
);
</syntaxhighlight>
=={{header|VTL-2}}==
<syntaxhighlight lang="vtl2">10 B=99
20 #=200
30 ?=" of beer on the wall,"
40 #=200
50 ?=" of beer,"
60 ?="Take ";
70 #=B=1*100
80 ?="one";
90 #=110
100 ?="it";
110 ?=" down and pass it around,"
120 B=B-1
130 #=200
140 ?=" of beer on the wall!"
150 ?=""
160 #=B=0=0*20
170 #=999
200 ;=!
210 #=B=0*270
220 ?=B
230 ?=" bottle";
240 #=B=1*;
250 ?="s";
260 #=;
270 ?="No more";
280 #=!+10</syntaxhighlight>
=={{header|Wart}}==
Line 12,718 ⟶ 13,849:
=={{header|Whenever}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|Whitespace}}==
See [[99 Bottles of Beer/EsoLang]]
=={{header|Wortel}}==
<
0 "0 bottles of beer on the wall\n0 bottles of beer\nbetter go to the store and buy some more."
"{@x} bottle{@?@x{1 @e 's}} of beer on the wall\n{@x} bottle{@?@x{1 @e 's}} of beer\nTake one down, pass it around"
}</
=={{header|Wrapl}}==
<
IMP IO.Terminal USE Out;
Line 12,744 ⟶ 13,878:
Out:write(verse[2,0]@(String.T, "") + verse[1]);
END Bottles.</
=={{header|Wren}}==
<
System.print("%(i) bottles of beer on the wall,")
System.print("%(i) bottles of beer,")
System.print("Take one down, pass it around,")
System.print("%(i - 1) bottles of beer on the wall.\n")
}</
=={{header|X10}}==
<
public static def main(args: Rail[String]){
val beerSong: NinetyNineBottles = NinetyNineBottles.make(99);
Line 12,821 ⟶ 13,955:
return "Take one down and pass it around, ";
}
}</
=={{header|X86 Assembly}}==
Line 12,827 ⟶ 13,961:
=={{header|XBS}}==
<
while (Bottles > 0){
log(Bottles+" bottles of beer on the wall,");
Line 12,834 ⟶ 13,968:
Bottles-=1;
log(Bottles+" bottles of beer on the wall");
}</
=={{header|xEec}}==
Line 12,841 ⟶ 13,975:
=={{header|Xojo}}==
Place the following in the '''Run''' event handler of a Console application:
<
While bottles > 0
Print(bottles.ToText + " bottles of beer on the wall,")
Line 12,849 ⟶ 13,983:
Print(bottles.ToText + " bottles of beer on the wall.")
Print ""
Wend</
=={{header|XPath}}==
Line 12,855 ⟶ 13,989:
A solution written in pure XPath 3.0 (using XSLT as a host language).
<
<xsl:output method="text"/>
<xsl:template match="/">
Line 12,869 ⟶ 14,003:
/>
</xsl:template>
</xsl:stylesheet></
=={{header|XPL0}}==
<
int B;
[B:= 99;
Line 12,881 ⟶ 14,015:
IntOut(0, B); Text(0, " bottles of beer on the wall^M^J^J");
until B=0;
]</
=={{header|XSLT}}==
Line 12,889 ⟶ 14,023:
To run, transform any document with this stylesheet (the input document is ignored).
<
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="utf-8"/>
Line 12,962 ⟶ 14,096:
</xsl:template>
</xsl:stylesheet></
===XSLT 3.0===
Line 12,975 ⟶ 14,109:
* use of text value templates (using "{ XPath code }") [first available XSLT 3, see https://www.w3.org/TR/xslt-30/#text-value-templates]
<
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="3.0">
Line 12,994 ⟶ 14,128:
</xsl:iterate>
</xsl:template>
</xsl:stylesheet></
=={{header|xTalk}}==
<syntaxhighlight lang="livecode">
function beerMe numberOfBottles
put "XX bottles of beer on the wall" into verseA
put "Take one down, pass it around" into verseB
repeat with N = numberOfBottles down to 1
put replaceText(verseA,"XX",N) & cr & word 1 to 4 of \
replaceText(verseA,"XX",N) & cr & verseB & cr & replaceText(verseA,"XX",N-1) \
& cr & cr after theSong
end repeat
return theSong
end beerMe
</syntaxhighlight>
=={{header|Yabasic}}==
<
if i=0 return "no more bottles of beer"
if i=1 return "1 bottle of beer"
Line 13,005 ⟶ 14,153:
for i = 99 to 1 step -1
print bottle$(i), " on the wall, \n", bottle$(i), "\n", "take one down, pass it around,\n", bottle$(i - 1), " on the wall.\n"
next</
=={{header|Yacas}}==
<syntaxhighlight lang="yacas">
For (b := 99, b > 0, b--)
Echo({b, "bottle(s) of beer on the wall," : Nl(),
Line 13,015 ⟶ 14,163:
"Take one down, pass it around," : Nl(),
b - 1, "bottle(s) of beer on the wall." : Nl()});
</syntaxhighlight>
=={{header|YAMLScript}}==
<syntaxhighlight lang="yaml">
#!/usr/bin/env ys-0
# Print the verses to "99 Bottles of Beer"
#
# usage:
# ys 99-bottles.ys [<count>]
defn main(number=99):
each [n (number .. 1)]:
say: paragraph(n)
defn paragraph(num): |
$bottles(num) of beer on the wall,
$bottles(num) of beer.
Take one down, pass it around.
$bottles(num - 1) of beer on the wall.
defn bottles(n):
cond:
n == 0 : 'No more bottles'
n == 1 : '1 bottle'
=> : "$n bottles"
</syntaxhighlight>
=={{header|Yorick}}==
=== Looped version ===
<
while(bottles) {
write, format=" %d bottles of beer on the wall\n", bottles;
Line 13,027 ⟶ 14,201:
write, "Take one down, pass it around";
write, format=" %d bottles of beer on the wall\n\n", --bottles;
}</
=== Vectorized version ===
<
song += "%d bottles of beer\n";
song += "Take one down, pass it around\n";
song += "%d bottles of beer on the wall\n";
beer = indgen(99:1:-1);
write, format=song, beer, beer, beer-1;</
=={{header|Z80 Assembly}}==
See [[99 Bottles of Beer/Assembly]]
=={{header|Zig}}==
{{trans|C}}
<syntaxhighlight lang="zig">const print = @import("std").debug.print;
pub fn main() void {
var i: u8 = 99;
while (i > 2) : (i-= 1) {
print(
\\{} bottles of beer on the wall, {} bottles of beer.
\\Take one down and pass it around, {} bottles of beer on the wall.
\\
\\
, .{i, i, i-1});
}
print(
\\2 bottles of beer on the wall, 2 bottles of beer.
\\Take one down and pass it around, 1 bottle of beer on the wall.
\\
\\1 bottle of beer on the wall, 1 bottle of beer.
\\Take one down and pass it around, no more bottles of beer on the wall.
\\
\\No more bottles of beer on the wall, no more bottles of beer.
\\Go to the store and buy some more, 99 bottles of beer on the wall.
, .{});
}</syntaxhighlight>
=={{header|zkl}}==
<
println(beers(n), " on the wall, ", beers(n).toLower(), ".\n",
n==0 and ("Go to the store and buy some more, 99 bottles of beer") or
Line 13,050 ⟶ 14,248:
(n==0 and "No more bottles" or (n==1 and "1 bottle" or "" + n + " bottles"))
+ " of beer"
}</
{{out}}
<pre>
|