99 bottles of beer: Difference between revisions

m
Automated syntax highlighting fixup (second round - minor fixes)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 44:
{{trans|Python}}
 
<syntaxhighlight lang="11l">L(i) (99..1).step(-1)
print(i‘ bottles of beer on the wall’)
print(i‘ bottles of beer’)
Line 63:
 
=={{header|8th}}==
<syntaxhighlight lang="forth">
\ 99 bottles of beer on the wall:
: allout "no more bottles" ;
Line 87:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang=AArch64"aarch64 Assemblyassembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program bootleBeer64.s */
Line 172:
</syntaxhighlight>
=={{header|ABAP}}==
<syntaxhighlight lang=ABAP"abap">REPORT z99bottles.
 
DATA lv_no_bottles(2) TYPE n VALUE 99.
Line 193:
or (With ABAP 7.40)
 
<syntaxhighlight lang=ABAP"abap">REPORT YCL_99_BOTTLES.
 
DATA it_99_bottles TYPE TABLE OF string WITH EMPTY KEY.
Line 217:
 
=={{header|Action!}}==
<syntaxhighlight lang=Action"action!">PROC Bottles(BYTE i)
IF i=0 THEN
Print("No more")
Line 272:
 
=={{header|ActionScript}}==
<syntaxhighlight lang=ActionScript"actionscript">for(var numBottles:uint = 99; numBottles > 0; numBottles--)
{
trace(numBottles, " bottles of beer on the wall");
Line 282:
=={{header|Ada}}==
===Simple version===
<syntaxhighlight lang="ada">with Ada.Text_Io; use Ada.Text_Io;
procedure Bottles is
Line 296:
===Concurrent version===
with 1 task to print out the information and 99 tasks to specify the number of bottles
<syntaxhighlight lang=Ada"ada">with Ada.Text_Io; use Ada.Text_Io;
 
procedure Tasking_99_Bottles is
Line 337:
 
=={{header|Aime}}==
<syntaxhighlight lang="aime">integer bottles;
 
bottles = 99;
Line 349:
 
=={{header|Algae}}==
<syntaxhighlight lang="algae">
# 99 Bottles of Beer on the Wall
# in Algae
Line 373:
 
=={{header|ALGOL 60}}==
<syntaxhighlight lang="algol60">begin
integer n;
 
Line 396:
{{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}} -->
<syntaxhighlight lang="algol68">main:(
FOR bottles FROM 99 TO 1 BY -1 DO
printf(($z-d" bottles of beer on the wall"l$, bottles));
Line 406:
 
=={{header|ALGOL-M}}==
<syntaxhighlight lang="algol">
BEGIN
 
Line 442:
 
=={{header|AmigaE}}==
<syntaxhighlight lang="amigae">PROC main()
DEF t: PTR TO CHAR,
s: PTR TO CHAR,
Line 458:
=={{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.
<syntaxhighlight lang="xml"><?xml version="1.0"?>
<project name="n bottles" default="99_bottles">
 
Line 502:
 
=={{header|Apex}}==
<syntaxhighlight lang="apex">
for(Integer i = 99; i=0; i--){
system.debug(i + ' bottles of beer on the wall');
Line 545:
===Iteration===
 
<syntaxhighlight lang=Applescript"applescript">repeat with beerCount from 99 to 1 by -1
set bottles to "bottles"
if beerCount < 99 then
Line 562:
 
===Declaration===
<syntaxhighlight lang=AppleScript"applescript">-- BRIEF -----------------------------------------------------------------------
on run
set localisations to ¬
Line 680:
 
=={{header|Arbre}}==
<syntaxhighlight lang=Arbre"arbre">
bottle(x):
template: '
Line 707:
 
=={{header|Argile}}==
<syntaxhighlight lang=Argile"argile">use std
 
let X be an int
Line 732:
=={{header|ArnoldC}}==
As ArnoldC does not feature string concatenation, the numbers of bottles and the rest of the parts of the lyrics are printed on separate lines.
<syntaxhighlight lang=ArnoldC"arnoldc">IT'S SHOWTIME
HEY CHRISTMAS TREE is0
YOU SET US UP @NO PROBLEMO
Line 758:
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">s: "s"
 
loop 99..1 'i [
Line 774:
 
=={{header|AsciiDots}}==
<syntaxhighlight lang=AsciiDots"asciidots"> /-99#-.
/>*$_#-$_" bottles of beer on the wall, "-$_#-$" bottles of beer."\
|[-]1#-----" ,dnuora ti ssap dna nwod eno ekaT"_$-----------------/
Line 788:
 
=={{header|Astro}}==
<syntaxhighlight lang="python">fun bottles(n): match __args__:
(0) => "No more bottles"
(1) => "1 bottle"
Line 802:
 
=={{header|Asymptote}}==
<syntaxhighlight lang=Asymptote"asymptote">// Rosetta Code problem: http://rosettacode.org/wiki/99_bottles_of_beer
// by Jjuanhdez, 05/2022
 
Line 824:
 
=={{header|ATS}}==
<syntaxhighlight lang=ATS"ats">//
#include
"share/atspre_staload.hats"
Line 866:
For example, just a sixpack:
 
<syntaxhighlight lang="awk"># usage: gawk -v i=6 -f beersong.awk
 
function bb(n) {
Line 923:
Pauses are added to accommodate the small calculator screen so all of the text can be read.
 
<syntaxhighlight lang="axe">99→B
While B
Disp B▶Dec," BOTTLES OF","BEER ON THE WALL"
Line 935:
 
=={{header|Babel}}==
<syntaxhighlight lang="babel">-- beer.sp
 
{b " bottles of beer" <
Line 1,030:
 
<!--- works with C syntax highlighting --->
<syntaxhighlight lang="c">
const bottle = " bottle"
const plural = "s"
Line 1,180:
{{works with|GNU bc|1.06}}
 
<syntaxhighlight lang=Bc"bc">i = 99;
while ( 1 ) {
print i , " bottles of beer on the wall\n";
Line 1,196:
 
=={{header|BCPL}}==
<syntaxhighlight lang=BCPL"bcpl">get "libhdr"
 
let number(n) be
Line 1,233:
Straightforward implementation, displaying the full lyrics given on [ http://99-bottles-of-beer.net/ ]
 
<syntaxhighlight lang=Beeswax"beeswax">
> NN p
> d#_8~2~(P~3~.~1~>{` bottles of beer on the wall, `{` bottles of beer.`q
Line 1,247:
Output is the same as in the straightforward version.
 
<syntaxhighlight lang=Beeswax"beeswax">
#D@.9~2~@M.7~P9zE `N`p
DMM@.9@.~2~.++~5zE `n`>`o`p
Line 1,264:
 
=={{header|BlitzMax}}==
<syntaxhighlight lang="blitzmax">local bot:int = 99
 
repeat
Line 1,282:
=={{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.
<syntaxhighlight lang="bloop">
DEFINE PROCEDURE ''MINUS'' [A,B]:
BLOCK 0: BEGIN
Line 1,331:
 
Code to save to BottlesOfBeer.bra:
<syntaxhighlight lang="bracmat">{BottlesOfBeer.bra
 
See http://99-bottles-of-beer.net/}
Line 1,396:
 
=={{header|Brat}}==
<syntaxhighlight lang="brat">99.to 2 { n |
p "#{n} bottles of beer on the wall, #{n} bottles of beer!"
p "Take one down, pass it around, #{n - 1} bottle#{true? n > 2 's' ''} of beer on the wall."
Line 1,405:
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">Pl ← {(𝕩≠1)/"s"}
{𝕨∾(@+10)∾𝕩}´{(•Fmt 𝕨)∾" "∾𝕩}´¨∾{
Line 1,424:
{{trans|C++}}
=== The simple solution ===
<syntaxhighlight lang="c">/*
* 99 Bottles, C, KISS (i.e. keep it simple and straightforward) version
*/
Line 1,454:
 
=== A recursive solution ===
<syntaxhighlight lang="c">#include <stdio.h>
 
int main(int argc, char *argv[])
Line 1,473:
 
=== Code golf ===
<syntaxhighlight lang="c">#include <stdio.h>
main(){_=100;while(--_)printf("%i bottle%s of beer in the wall,\n%i bottle%"
"s of beer.\nTake one down, pass it round,\n%s%s\n\n",_,_-1?"s":"",_,_-1?"s"
Line 1,485:
Well, with the preprocessor, that's indeed possible:
 
<syntaxhighlight lang="c">#include <stdlib.h>
#include <stdio.h>
 
Line 1,519:
 
===The bottled version===
WYSIWYG (with correct plurals and can buy some more):<syntaxhighlight lang="c"> int b =99,u =1;
#include<stdio.h>
char *d[16],y[]
Line 1,556:
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">using System;
 
class Program
Line 1,588:
=== C#6 Implementation ===
{{works with|C sharp|C#|6+}}
<syntaxhighlight lang="csharp">using System;
class Program
{
Line 1,603:
{{works with|C sharp|C#|6+}}
 
<syntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 1,618:
 
=== Flexible Version ===
<syntaxhighlight lang="csharp">using System;
using System.Globalization;
class Program
Line 1,663:
{{works with|C sharp|C#|3+}}
 
<syntaxhighlight lang="csharp">class songs
{
static void Main(string[] args)
Line 1,713:
{{works with|C sharp|C#|3+}}
 
<syntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 1,736:
 
=== A Fun One ===
<syntaxhighlight lang="csharp">string[] bottles = { "80 Shilling",
"Abita Amber",
"Adams Broadside Ale",
Line 1,869:
 
=== Using recursion ===
<syntaxhighlight lang="csharp">public static void BottlesSong(int numberOfBottles)
{
if (numberOfBottles > 0)
Line 1,883:
 
=== Using a While Loop ===
<syntaxhighlight lang="csharp">static void Main(string[] args)
{
int numBottles = 99;
Line 1,908:
=== The simple solution ===
{{works with|g++|4.8.1}}
<syntaxhighlight lang="cpp">#include <iostream>
using std::cout;
 
Line 1,927:
Of course, the output of the program always looks the same. One may therefore question why the program has to do all that tedious subtracting during runtime. Couldn't the compiler just generate the code to output the text, with ready-calculated constants? Indeed, it can, and the technique is called template metaprogramming. The following short code gives the text without containing a single variable, let alone a loop:
 
<syntaxhighlight lang="cpp">#include <iostream>
 
template<int max, int min> struct bottle_countdown
Line 1,958:
=== A function template solution ===
Function templates are a different approach to template metaprogramming:
<syntaxhighlight lang="cpp">#include <iostream>
 
template<unsigned int N> void bottles(){
Line 1,981:
 
=== A Recursive solution ===
<syntaxhighlight lang="cpp">#include <iostream>
using namespace std;
void rec(int bottles)
Line 2,006:
Of course, with the template metaprogramming solution, the program has still do the conversion of numbers to strings at runtime, and those function calls also cost unnecessary time. Couldn't we just compose the complete text at compile time, and just output it at run time? Well, with the preprocessor, that's indeed possible:
 
<syntaxhighlight lang="cpp">#include <iostream>
#include <ostream>
 
Line 2,039:
=== Bottled Version ===
 
<syntaxhighlight lang="cpp"> //>,_
//Beer Song>,_
#include <iostream>
Line 2,078:
 
=={{header|Ceylon}}==
<syntaxhighlight lang="ceylon">shared void ninetyNineBottles() {
String bottles(Integer count) =>
Line 2,095:
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">
/***********************************************************************
* Chapel implementation of "99 bottles of beer"
Line 2,171:
=={{header|Cind}}==
 
<syntaxhighlight lang="cind">
execute() {
 
Line 2,206:
=={{header|Clay}}==
 
<syntaxhighlight lang=Clay"clay">/* A few options here: I could give n type Int; or specify that n is of any
numeric type; but here I just let it go -- that way it'll work with anything
that compares with 1 and that printTo knows how to convert to a string. And
Line 2,229:
 
=={{header|Clio}}==
<syntaxhighlight lang="clio">fn bottle n:
n -> if = 0: 'no more bottles'
elif = 1: n + ' bottle'
Line 2,243:
=={{header|CLIPS}}==
 
<syntaxhighlight lang="clips">(deffacts beer-bottles
(bottles 99))
 
Line 2,264:
 
=={{header|Clojure}}==
<syntaxhighlight lang=Clojure"clojure">(defn paragraph [num]
(str num " bottles of beer on the wall\n"
num " bottles of beer\n"
Line 2,280:
Or, using cl-format:
{{trans|Common Lisp}}
<syntaxhighlight lang=Clojure"clojure">(clojure.pprint/cl-format
true
"~{~[~^~]~:*~D bottle~:P of beer on the wall~%~:*~D bottle~:P of beer
Line 2,287:
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">bottles = proc (n: int) returns (string)
if n<0 then return("99 bottles")
elseif n=0 then return("No more bottles")
Line 2,326:
{{works with|OpenCOBOL|1.1}}
Free form version.
<syntaxhighlight lang="cobol">identification division.
program-id. ninety-nine.
environment division.
Line 2,432:
 
Another free-form version, without using <code>DISPLAY NO ADVANCING</code>.
<syntaxhighlight lang="cobol">identification division.
program-id. ninety-nine.
environment division.
Line 2,556:
 
A more concise version that adheres to the minimum guidelines. Leading zeros are not suppressed. (OpenCOBOL - 1.1.0)
<syntaxhighlight lang="cobol">program-id. ninety-nine.
data division.
working-storage section.
Line 2,574:
 
=={{header|CoffeeScript}}==
<syntaxhighlight lang="coffeescript">
bottlesOfBeer = (n) ->
"#{n} bottle#{if n is 1 then '' else 's'} of beer"
Line 2,588:
With completely different approach...
 
<syntaxhighlight lang="coffeescript">for j in [99..1]
x=''
x += [j,j-1,'\nTake one down, pass it around\n'," bottles of beer",' on the wall\n'][i] for i in [0,3,4,0,3,2,1,3,4]
Line 2,596:
or as a one liner...
 
<syntaxhighlight lang="coffeescript">console.log( if (j+2)%4 then (x=Math.round j/4)+" bottle#{if x-1 then 's' else ''} of beer#{if (j+1)%4 then ' on the wall' else ''}" else "Take one down, pass it around" ) for j in [396..1]</syntaxhighlight>
 
or another completely different one liner
 
<syntaxhighlight lang="coffeescript">((console.log if i is 2 then "Take one down, pass it around" else "#{b-!(i-1%4)} bottle#{if 4*b+i<10 and b-i then '' else 's'} of beer#{if i%3 then ' on the wall' else ''}") for i in [4..1]) for b in [99..1]</syntaxhighlight>
 
=={{header|ColdFusion}}==
=== Classic tag based CFML ===
<syntaxhighlight lang="cfm"><cfoutput>
<cfloop index="x" from="99" to="0" step="-1">
<cfset plur = iif(x is 1,"",DE("s"))>
Line 2,616:
 
=== CFScript ===
<syntaxhighlight lang="cfm"><cfscript>
for (x=99; x gte 1; x--) {
plur = iif(x==1,'',DE('s'));
Line 2,624:
 
=={{header|Comal}}==
<syntaxhighlight lang="comal">0010 DIM itone$(0:1)
0020 itone$(0):="one";itone$(1):="it"
0030 FOR b#:=99 TO 1 STEP -1 DO
Line 2,650:
=={{header|Comefrom0x10}}==
 
<syntaxhighlight lang="cf0x10">bottles = ' bottles '
remaining = 99
one_less_bottle = remaining
Line 2,689:
 
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub Bottles(n: uint8) is
Line 3,224:
 
=={{header|Crystal}}==
<syntaxhighlight lang="crystal">99.downto(1) do |n|
puts "#{n} bottle#{n > 1 ? "s" : ""} of beer on the wall"
puts "#{n} bottle#{n > 1 ? "s" : ""} of beer"
Line 3,240:
 
Based on Steward Gordon's code at: [http://99-bottles-of-beer.net/language-d-721.html 99-bottles-of-beer.net].
<syntaxhighlight lang="d">import std.stdio;
 
void main() {
Line 3,265:
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.
 
<syntaxhighlight lang="d">import std.stdio, std.conv;
 
string bottles(in size_t num) pure {
Line 3,294:
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,320:
=={{header|Dart}}==
// Making use of polymorphism
<syntaxhighlight lang="dart">main() {
BeerSong beerSong = BeerSong();
//pass a 'starting point' and 'end point' as parameters respectively
Line 3,386:
{{works with|GNU dc}}
{{works with|OpenBSD dc}}
<syntaxhighlight lang=Dc"dc">[
dnrpr
dnlBP
Line 3,419:
 
{{works with|AT&T dc}}
<syntaxhighlight lang=Dc"dc">[
plAP
plBP
Line 3,454:
 
=={{header|DBL}}==
<syntaxhighlight lang="text">;
;===============================================================================
; Oringinal Author: Bob Welton (welton@pui.com)
Line 3,510:
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec bottles(byte b) void:
if b=0 then write("No more") else write(b) fi;
write(" bottle");
Line 3,535:
=={{header|Dyalect}}==
{{trans|Swift}}
<syntaxhighlight lang="dyalect">for i in 99^-1..1 {
print("\(i) bottles of beer on the wall, \(i) bottles of beer.")
let next = i is 1 ? "no" : i - 1
Line 3,542:
 
=={{header|Dylan}}==
<syntaxhighlight lang="dylan">Module: bottles
define method bottles (n :: <integer>)
for (n from 99 to 1 by -1)
Line 3,554:
 
=={{header|Déjà Vu}}==
<syntaxhighlight lang="dejavu">plural i:
if = 1 i "" "s"
 
Line 3,573:
 
=={{header|DIBOL-11}}==
<syntaxhighlight lang=DIBOL"dibol-11">
;
;===============================================================================
Line 3,649:
</syntaxhighlight>
=={{header|E}}==
<syntaxhighlight lang="e">def bottles(n) {
return switch (n) {
match ==0 { "No bottles" }
Line 3,665:
 
=={{header|ECL}}==
<syntaxhighlight lang=ECL"ecl">
Layout := RECORD
UNSIGNED1 RecID1;
Line 3,691:
 
=={{header|Egel}}==
<syntaxhighlight lang=Egel"egel">
import "prelude.eg"
import "io.ego"
Line 3,711:
 
=={{header|EGL}}==
<syntaxhighlight lang=EGL"egl">program TestProgram type BasicProgram {}
function main()
Line 3,735:
 
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">
class
APPLICATION
Line 3,779:
 
An alternative version written using the across-loop construct.
<syntaxhighlight lang="eiffel">
output_lyrics
-- Output the lyrics to 99-bottles-of-beer.
Line 3,807:
=={{header|Ela}}==
 
<syntaxhighlight lang=Ela"ela">open list
beer 1 = "1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around"
Line 3,819:
=={{header|Elena}}==
ELENA 5.0 :
<syntaxhighlight lang="elena">import system'routines;
import extensions;
import extensions'routines;
Line 3,883:
 
=={{header|Elixir}}==
<syntaxhighlight lang=Elixir"elixir">defmodule Bottles do
def run do
Enum.each 99..1, fn idx ->
Line 3,901:
 
=={{header|Elm}}==
<syntaxhighlight lang=Elm"elm">module Main exposing (main)
 
import Html
Line 3,930:
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang=Lisp"lisp">(let ((i 99))
(while (> i 0)
(message "%d bottles of beer on the wall" i)
Line 3,939:
 
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">-module(beersong).
-export([sing/0]).
-define(TEMPLATE_0, "~s of beer on the wall, ~s of beer.~nGo to the store and buy some more, 99
Line 3,981:
=={{header|Euphoria}}==
{{works with|Euphoria|4.0.0}}
<syntaxhighlight lang=Euphoria"euphoria">constant
bottles = "bottles",
bottle = "bottle"
Line 4,010:
end for</syntaxhighlight>
 
<syntaxhighlight lang=Euphoria"euphoria">-- An alternate version
 
include std/console.e
Line 4,028:
end for</syntaxhighlight>
 
<syntaxhighlight lang=Euphoria"euphoria">-- yet another version:
 
include std/console.e
Line 4,053:
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">#light
let rec bottles n =
let (before, after) = match n with
Line 4,067:
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: io kernel make math math.parser math.ranges sequences ;
 
: bottle ( -- quot )
Line 4,091:
 
=={{header|Falcon}}==
<syntaxhighlight lang="falcon">for i in [99:1]
> i, " bottles of beer on the wall"
> i, " bottles of beer"
Line 4,099:
 
A more robust version to handle plural/not plural conditions
<syntaxhighlight lang="falcon">for i in [99:1]
plural = (i != 1) ? 's' : ""
> @ "$i bottle$plural of beer on the wall"
Line 4,113:
copied from [http://99-bottles-of-beer.net/language-ferite-1281.html?PHPSESSID=b563ec9a2791f6c3cc917c22b17dc542 99-bottles-of-beer.net].
 
<syntaxhighlight lang="ferite">uses "console";
 
number bottles = 99;
Line 4,135:
 
=={{header|Fexl}}==
<syntaxhighlight lang="fexl">
\suffix=(\n eq n 1 "" "s")
\sing_count=(\n put [n " bottle" (suffix n) " of beer"])
Line 4,174:
 
=={{header|FOCAL}}==
<syntaxhighlight lang=FOCAL"focal">01.10 S N=99
01.15 D 2;T " OF BEER ON THE WALL,",!
01.20 D 2;T " OF BEER,",!
Line 4,222:
 
=={{header|Forth}}==
<syntaxhighlight lang="forth">:noname dup . ." bottles" ;
:noname ." 1 bottle" ;
:noname ." no more bottles" ;
Line 4,238:
 
Version 2: create a beer language and write the program
<syntaxhighlight lang="forth">DECIMAL
: BOTTLES ( n -- )
DUP
Line 4,275:
 
Forth Console Output
<syntaxhighlight lang=Forth"forth">2 beers
2 bottles of beer on the wall,
2 bottles of beer ,
Line 4,290:
=={{header|Fortran}}==
===F90 version===
<syntaxhighlight lang="fortran">program bottlestest
 
implicit none
Line 4,316:
 
===MPI version===
<syntaxhighlight lang="fortran">program bottlesMPI
 
implicit none
Line 4,351:
===Fortran 2003/2008 OOP version===
Works with GNU gfortran 5.0.0 and Intel ifort 15.0.2
<syntaxhighlight lang="fortran">
module song_typedefs
implicit none
Line 4,491:
{{Works with|Frege|3.21.586-g026e8d7}}
 
<syntaxhighlight lang="frege">module Beer where
 
main = mapM_ (putStrLn . beer) [99, 98 .. 0]
Line 4,506:
=={{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.
<syntaxhighlight lang="frink">
units = array[units[volume]]
showApproximations[false]
Line 4,563:
 
=={{header|FunL}}==
<syntaxhighlight lang="funl">val
numbers = {1:'one', 2:'two', 3:'three', 4:'four', 5:'five', 6:'six', 7:'seven',
8:'eight', 9:'nine', 10:'ten', 11:'eleven', 12:'twelve'}
Line 4,595:
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
Line 4,615:
Implementation of the code '99 bottles of beer' written in Visual Basic. Code tested in Gambas 3.15.2
 
<syntaxhighlight lang=Gambas"gambas">' Gambas module file
 
Public Const bottlesofbeer As String = " bottles of beer."
Line 4,654:
 
=={{header|GAP}}==
<syntaxhighlight lang="gap">Bottles := function(n)
local line, i, j, u;
line := function(n)
Line 4,678:
 
=={{header|Genie}}==
<syntaxhighlight lang="genie">[indent=4]
def plural(n:uint):string
return (n == 1) ? "" : "s"
Line 4,707:
 
=={{header|gnuplot}}==
<syntaxhighlight lang="gnuplot">if (!exists("bottles")) bottles = 99
print sprintf("%i bottles of beer on the wall", bottles)
print sprintf("%i bottles of beer", bottles)
Line 4,718:
=={{header|Go}}==
===No sense of humor===
<syntaxhighlight lang="go">package main
 
import "fmt"
Line 4,744:
===Typoglycemic===
With code from RC tasks Number names, Knuth shuffle.
<syntaxhighlight lang="go">package main
 
import (
Line 4,865:
=={{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.
<syntaxhighlight lang="go!">--
-- 99 Bottles of Beer in Go!
-- John Knottenbelt
Line 4,898:
 
=={{header|Golfscript}}==
<syntaxhighlight lang="golfscript">[296,{3/)}%-1%["No more"]+[" bottles":b]294*[b-1<]2*+[b]+[" of beer on the wall\n".8<"\nTake one down, pass it around\n"+1$n+]99*]zip</syntaxhighlight>
 
=={{header|Golo}}==
<syntaxhighlight lang="golo">module Bottles
 
augment java.lang.Integer {
Line 4,922:
 
=={{header|Gosu}}==
<syntaxhighlight lang="gosu">
for (i in 99..0) {
 
Line 4,939:
===Basic Solution===
With a closure to handle special cardinalities of bottles.
<syntaxhighlight lang="groovy">def bottles = { "${it==0 ? 'No more' : it} bottle${it==1 ? '' : 's' }" }
 
99.downto(1) { i ->
Line 4,952:
=== Single Print Version ===
Uses a single print algorithm for all four lines. Handles cardinality on bottles, uses 'No more' instead of 0.
<syntaxhighlight lang="groovy">298.downto(2) {
def (m,d) = [it%3,(int)it/3]
print "${m==1?'\n':''}${d?:'No more'} bottle${d!=1?'s':''} of beer" +
Line 4,960:
===Bottomless Beer Solution===
Using more closures to create a richer lyrical experience.
<syntaxhighlight lang="groovy">def bottles = { "${it==0 ? 'No more' : it} bottle${it==1 ? '' : 's' }" }
 
def initialState = {
Line 4,995:
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:
 
<syntaxhighlight lang="guiss">Start,Programs,Accessories,Calculator,Button:9,Button:9,
Button:[hyphen],Button:1,Button:[equals],Button:[hyphen],Button:1,Button:[equals],
Button:[hyphen],Button:1,Button:[equals],Button:[hyphen],Button:1,Button:[equals],
Line 5,004:
 
=={{header|Halon}}==
<syntaxhighlight lang="halon">$plural = "s";
$x = 99;
while ($x > 0) {
Line 5,023:
A relatively concise solution:
 
<syntaxhighlight lang="haskell">main = mapM_ (putStrLn . beer) [99, 98 .. 0]
beer 1 = "1 bottle of beer on the wall\n1 bottle of beer\nTake one down, pass it around"
beer 0 = "better go to the store and buy some more."
Line 5,033:
As a list comprehension:
 
<syntaxhighlight lang="haskell">import qualified Char
 
main = putStr $ concat
Line 5,053:
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.
 
<syntaxhighlight lang="haskell">{-# LANGUAGE TemplateHaskell #-}
-- build with "ghc --make beer.hs"
module Main where
Line 5,085:
Is there something just a little prickly and displeasing about (++) ?
Monoid (<>) is less spiky, but neither is needed when 'bottle' is written backwards.
<syntaxhighlight lang="haskell">location, distribution, solution :: String
[location, distribution, solution] =
[ "on the wall",
Line 5,119:
=={{header|Haxe}}==
=== Simple solution ===
<syntaxhighlight lang="haxe">class RosettaDemo
{
static public function main()
Line 5,157:
Let's generate that print with macro.
 
<syntaxhighlight lang="haxe">class Bottles {
 
static public function main () : Void {
Line 5,192:
 
=={{header|hexiscript}}==
<syntaxhighlight lang="hexiscript">fun bottles amount beverage location
let bottle " bottles of "
if amount = 0; let amount "No more"
Line 5,216:
 
=={{header|HicEst}}==
<syntaxhighlight lang="hicest">DO x = 99, 1, -1
WRITE() x , "bottles of beer on the wall"
BEEP("T16 be be be bH bH bH be be be 2be ")
Line 5,233:
The default is 99 bottles, but it can be modified by the parameter.
 
<syntaxhighlight lang="holyc">U0 BottlesOfBeer (I64 initial=99) {
// This is made I64 rather than U64
// Because, a U64 would overflow
Line 5,265:
 
=={{header|Hoon}}==
<syntaxhighlight lang=Hoon"hoon">
:- %say
|= [* * [bottles=_99 ~]]
Line 5,292:
=={{header|Hope}}==
El código es de Wolfgang Lohmann (wlohmann@informatik.uni-rostock.de)
<syntaxhighlight lang="hope">dec app :( list ( char ) X list ( char )) -> list ( char ) ;
dec i2c : num -> char;
dec i2s : num -> list(char);
Line 5,332:
 
=={{header|Huginn}}==
<syntaxhighlight lang="huginn">#! /bin/sh
exec huginn --no-argv -E "${0}" "${@}"
#! huginn
Line 5,359:
=={{header|HyperTalk}}==
El código es de Eric Carlson eric@bungdabba.com
<syntaxhighlight lang="hypertalk">on BeerSong99
BottlesOfBeer 99
end BeerSong99
Line 5,403:
The default is 99 bottles, but you can change this on the command line for
really long trips...
<syntaxhighlight lang="icon">procedure main(args)
numBeers := integer(args[1]) | 99
drinkUp(numBeers)
Line 5,432:
 
=={{header|IDL}}==
<syntaxhighlight lang=IDL"idl">Pro bottles
 
for i=1,99 do begin
Line 5,445:
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:
 
<syntaxhighlight lang=IDL"idl">Pro bottles_noloop
b=(reverse(shift(sindgen(100),-1)))[1:99]
b2=reverse(sindgen(99))
Line 5,456:
I found the above example very helpful but overdone. This is a more simple version:
 
<syntaxhighlight lang=IDL"idl">Pro bottles_noloop2
n_bottles=99
b1 = reverse(SINDGEN(n_bottles,START=1))
Line 5,467:
 
=={{header|Idris}}==
<syntaxhighlight lang=Idris"idris">
beerSong : Fin 100 -> String
beerSong x = verses x where
Line 5,490:
 
=={{header|Inform 6}}==
<syntaxhighlight lang="inform6">[ Bottles i;
if(i == 1) return "bottle";
 
Line 5,513:
=={{header|Inform 7}}==
=== Programmatic solution ===
<syntaxhighlight lang="inform7">Beer Hall is a room.
 
When play begins:
Line 5,527:
This solution uses in-game objects to represent the wall and the bottles.
 
<syntaxhighlight lang="inform7">Beer Hall is a room.
 
The plural of bottle of beer is bottles of beer. A bottle of beer is a kind of thing.
Line 5,550:
 
=={{header|Io}}==
<syntaxhighlight lang="io">bottles := method(i,
if(i==0, return "no more bottles of beer")
if(i==1, return "1 bottle of beer")
Line 5,565:
 
=={{header|Ioke}}==
<syntaxhighlight lang="ioke">bottle = method(i,
case(i,
0, "no more bottles of beer",
Line 5,579:
=={{header|J}}==
As posted at the [http://www.jsoftware.com/jwiki/Essays/99_Bottles_of_Beer J wiki]
<syntaxhighlight lang="j">bob =: ": , ' bottle' , (1 = ]) }. 's of beer'"_
bobw=: bob , ' on the wall'"_
beer=: bobw , ', ' , bob , '; take one down and pass it around, ' , bobw@<:
Line 5,595:
===Console===
MessageFormat's choice operator is used to properly format plurals.
<syntaxhighlight lang="java">import java.text.MessageFormat;
 
public class Beer {
Line 5,616:
 
'''Optimized for speed and few I/O operations'''
<syntaxhighlight lang="java">public class Beer {
public static void main(String[] args) {
int bottles = 99;
Line 5,632:
 
'''Recursive'''
<syntaxhighlight lang="java">public class Beer {
public static void main(String args[]) {
song(99);
Line 5,659:
{{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.
<syntaxhighlight lang="java">import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
Line 5,703:
=={{header|JavaScript}}==
===ES3-5===
<syntaxhighlight lang="javascript">var beer = 99;
while (beer > 0) {
var verse = [
Line 5,719:
 
===ES6===
<syntaxhighlight lang="javascript">let beer = 99;
while (beer > 0) {
let verse = `${beer} bottles of beer on the wall,
Line 5,731:
 
===Functional / Recursive===
<syntaxhighlight lang="javascript">var bottles = 99;
var songTemplate = "{X} bottles of beer on the wall \n" +
"{X} bottles of beer \n"+
Line 5,747:
 
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".
<syntaxhighlight lang="javascript">// Line breaks are in HTML
var beer; while ((beer = typeof beer === "undefined" ? 99 : beer) > 0) document.write( beer + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall<br>" + beer + " bottle" + (beer != 1 ? "s" : "") + " of beer<br>Take one down, pass it around<br>" + (--beer) + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall<br>" );</syntaxhighlight>
 
 
Legitimate "one-liner" with grammar check, using declarative methods.
<syntaxhighlight lang="javascript">Array.from(Array(100).keys()).splice(1).reverse().forEach(n => console.log(`${n} bottle${n !== 1 ? 's' : ''} of beer on the wall\n${n} bottle${n !== 1 ? 's' : ''} of beer\nTake one down, pass it around\n${n - 1} bottle${n - 1 !== 1 ? 's' : ''} of beer on the wall\n\n`));</syntaxhighlight>
 
 
Object Oriented
<syntaxhighlight lang="javascript">function Bottles(count) {
this.count = count || 99;
}
Line 5,784:
An alternative version:
 
<syntaxhighlight lang="javascript">function bottleSong(n) {
if (!isFinite(Number(n)) || n == 0) n = 100;
var a = '%% bottles of beer',
Line 5,804:
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">LIBRA
 
_beerlib == true;
Line 5,836:
=={{header|jq}}==
'''Minimalist:'''
<syntaxhighlight lang="jq">99
| (. - range(0;.+1) )
| "
Line 5,844:
\(.) bottles of beer on the wall"</syntaxhighlight>
{{out}}
<syntaxhighlight lang="sh">$ jq -n -r -f 99_bottles.jq
...
 
Line 5,862:
0 bottles of beer on the wall</syntaxhighlight>
'''Variant''':
<syntaxhighlight lang="jq">def sing:
def s: if . == 1 then "" else "s" end;
def bottles:
Line 5,878:
$bottles | tonumber | sing</syntaxhighlight>
{{out}}
<syntaxhighlight lang="sh">$ jq -r --arg bottles 99 -f 99_bottles_variant.jq
...
2 bottles of beer on the wall
Line 5,896:
 
=={{header|Jsish}}==
<syntaxhighlight lang="jsish">/* 99 Bottles, in Jsish */
function plural(n:number):string { return (bottles == 1) ? "" : "s"; }
function no(n:number):string { return (bottles == 0) ? "No" : n.toString(); }
Line 5,911:
=={{header|Julia}}==
'''one-liner'''
<syntaxhighlight lang="julia">for i = 99:-1:1 print("\n$i bottles of beer on the wall\n$i bottles of beer\nTake one down, pass it around\n$(i-1) bottles of beer on the wall\n") end</syntaxhighlight>
another solution, handling grammar cases "No more bottles", "1 bottle", "<n> bottles"
<syntaxhighlight lang="julia">bottles(n) = n==0 ? "No more bottles" :
n==1 ? "1 bottle" :
"$n bottles"
Line 5,926:
end</syntaxhighlight>
shorter, but more cryptic, version of the previous `bottles` function
<syntaxhighlight lang="julia">bottles(n) = "$(n==0 ? "No more" : n) bottle$(n==1 ? "" : "s")"</syntaxhighlight>
 
=={{header|K}}==
<syntaxhighlight lang="k">`0:\:{x[z],y,a,x[z],a,"Take one down, pass it around",a,x[z-1],y,a,a:"\n"}[{($x)," bottle",:[x=1;"";"s"]," of beer"};" on the wall"]'|1_!100</syntaxhighlight>
 
=={{header|Kabap}}==
<syntaxhighlight lang=Kabap"kabap">
// Loop that spits lyrics to "99 Bottles of Beer"
 
Line 5,949:
=={{header|Kitten}}==
 
<syntaxhighlight lang="kitten">99 bottles_of_beer_on_the_wall
 
define bottles_of_beer_on_the_wall (Int32 -> +IO):
Line 5,983:
 
=={{header|Klingphix}}==
<syntaxhighlight lang="text">include ..\Utilitys.tlhy
 
:bottles
Line 6,008:
 
=={{header|Klong}}==
<syntaxhighlight lang="k">bottles::{:[x=1;"bottle";"bottles"]}
itone::{:[x=1;"it";"one"]}
numno::{:[x=0;"no";x]}
Line 6,029:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">fun main(args: Array<String>) {
for (i in 99.downTo(1)) {
println("$i bottles of beer on the wall")
Line 6,044:
 
The signature file:
<syntaxhighlight lang=Lambda"lambda Prologprolog">sig bottles.
 
type println string -> o.
Line 6,052:
 
The module file:
<syntaxhighlight lang=Lambda"lambda Prologprolog">module bottles.
 
println Str :- print Str, print "\n".
Line 6,078:
Then we produce the desired output by setting the system to solve for this goal:
 
<syntaxhighlight lang=Lambda"lambda Prologprolog">[bottles] ?- bottles_song 99.</syntaxhighlight>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def beer
{lambda {:i}
Line 6,118:
 
=={{header|lang5}}==
<syntaxhighlight lang="lang5">: ~ 2 compress "" join ;
: verses(*)
dup " bottles of beer on the wall\n" ~ .
Line 6,132:
=== Simple loop ===
 
<syntaxhighlight lang=Lasso"lasso">local(
beer = 99,
song = ''
Line 6,150:
=== Query Expression ===
 
<syntaxhighlight lang=Lasso"lasso">(with beer in 99 to 1 by -1 select
#beer + ' bottles of beer on the wall' +
#beer + ' bottles of beer\n' +
Line 6,160:
=== Query Expression with Autocollect ===
 
<syntaxhighlight lang=Lasso"lasso">// this example adds an "s" to bottle until there is only 1 bottle left on the wall
 
local(s = 's')
Line 6,174:
=={{header|LaTeX}}==
===Recursive===
<syntaxhighlight lang=LaTeX"latex">\documentclass{minimal}
\newcounter{beer}
\newcommand{\verses}[1]{
Line 6,196:
Just for fun, this version uses Roman numerals.
 
<syntaxhighlight lang=LaTeX"latex">\documentclass{minimal}
\newcounter{beer}
\newcounter{showC}
Line 6,221:
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">
DATA:
bottles-in-the-wall is number
Line 6,253:
 
=={{header|Lhogho}}==
<syntaxhighlight lang="logo">to bottle :i
if :i = 0 [output "|No more bottles of beer|]
if :i = 1 [output "|One bottle of beer|]
Line 6,288:
 
=={{header|Limbo}}==
<syntaxhighlight lang=Limbo"limbo">
implement Beer;
 
Line 6,318:
 
=={{header|Lingo}}==
<syntaxhighlight lang=Lingo"lingo">repeat with i = 99 down to 2
put i & " bottles of beer on the wall"
put i & " bottles of beer"
Line 6,344:
 
=={{header|Logo}}==
<syntaxhighlight lang="logo">to bottles :n
if :n = 0 [output [No more bottles]]
if :n = 1 [output [1 bottle]]
Line 6,358:
 
=={{header|Logtalk}}==
<syntaxhighlight lang="logtalk">:- object(bottles).
 
:- initialization(sing(99)).
Line 6,386:
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">local bottles = 99
 
local function plural (bottles) if bottles == 1 then return '' end return 's' end
Line 6,400:
With a numeric for-loop and string formatting:
 
<syntaxhighlight lang="lua">verse = [[%i bottle%s of beer on the wall
%i bottle%s of beer
Take one down, pass it around
Line 6,413:
Using Lua relational operators and multiple return values:
 
<syntaxhighlight lang="lua">function bottles(i)
local s = i == 1 and "1 bottle of beer" or
i == 0 and "no more bottles of beer" or
Line 6,426:
 
=={{header|Lucid}}==
<syntaxhighlight lang="lucid">// Run luval with -s inside the lucid shell script
// The print out is a list of lines. So the output is not separated by new lines, rather
// by '[' and ']' -- I cant figure out how to do string concatenation with numbers in lucid.
Line 6,443:
=={{header|NATURAL}}==
El código es de Chris Bednara
<syntaxhighlight lang=NATURAL"natural">DEFINE DATA
LOCAL
01 #BOTTLES (I2)
Line 6,477:
 
=={{header|M4}}==
<syntaxhighlight lang="m4">define(`BOTTLES', `bottles of beer')dnl
define(`BOTTLE', `bottle of beer')dnl
define(`WALL', `on the wall')dnl
Line 6,489:
=={{header|MACRO-11}}==
 
<syntaxhighlight lang=MACRO"macro-11">
;
; 99 BOTTLES OF BEER
Line 6,639:
=={{header|MAD}}==
 
<syntaxhighlight lang=MAD"mad"> NORMAL MODE IS INTEGER
BOTLES = 99
Line 6,685:
{{libheader|jot}}
{{works with|BSD make}}
<syntaxhighlight lang="make">START = 99
UP != jot - 2 `expr $(START) - 1` 1
 
Line 6,717:
=== GNU make ===
{{works with|GNU make|3.81}}
<syntaxhighlight lang="make">PRED=`expr $* - 1`
 
1-bottles: 1-beer pass
Line 6,742:
===== Without using a shell command to decrement the counter =====
{{works with|GNU make|3.81}}
<syntaxhighlight lang="make">digits:=9 8 7 6 5 4 3 2 1 0
numbers:=$(foreach x,$(filter-out 0,$(digits)),$(foreach y,$(digits),$x$y))
numbers+=$(digits)
Line 6,804:
 
'''Long version''' (a real loop version made by Hisashi Iizawa)''':'''
<syntaxhighlight lang="malbolge">b'`;$9!=IlXFiVwwvtPO0)pon%IHGFDV|dd@Q=+^:('&Y$#m!1S|.QOO=v('98$65aCB}0i.Tw+QPU'7qK#I20jiDVgG
S(bt<%@#!7~|4{y1xv.us+rp(om%lj"ig}fd"cx``uz]rwvYnslkTonPfOjiKgJeG]\EC_X]@[Z<R;VU7S6QP2N1LK-I
,GF(D'BA#?>7~;:9y16w43s10)p-,l*#(i&%e#d!~``{tyxZpuXsrTTongOkdMhg`Hd]ba`_^W@[ZYXW9UNSRQPOHMLK
Line 7,052:
 
'''Short version''' (a just printing out the lyrics version made by Johannes E. Schindelin)''':'''
<syntaxhighlight lang="malbolge">DCBA@?>!}}{{yywwuussqqL-,+*)('&%$#c!a>v{z99wv5Ws3DpoA-lON*hg`_dc#a~_^Az>Z<;;uUN7
R5nO2~L/JzHe@ED'`N$?\7<;:W87C54us1N`.-nm*GF43gU#dRx=_N)sK&vo4Vrqji.z,Odvh'&e7Fb"
DlkAVhZS+Q9(7M_$o"110EhzgxFccbBNqLo\}}Y9z7gT4us1*/LKn87G(!&VeT/c?w|_M(xwY5XmVTjo
Line 7,152:
 
=={{header|Maple}}==
<syntaxhighlight lang=Maple"maple">seq( printf( "%d %s of beer on the wall,\n%d %s of beer.\nTake one down, pass it around,\n%d %s of beer on the wall.\n\n",
i, `if`( i<>1, "bottles", "bottle" ),
i, `if`( i<>1, "bottles", "bottle" ),
Line 7,159:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang=Mathematica"mathematica">Bottle[n_] := ToString[n] <> If[n==1," bottle"," bottles"] <> " of beer"
 
BottleSong[n_] := Speak[
Line 7,171:
 
=={{header|MATLAB}}==
<syntaxhighlight lang=MATLAB"matlab">function ninetyNineBottlesOfBeer()
 
disp( [ sprintf(['%d bottles of beer on the wall, %d bottles of beer.\n'...
Line 7,184:
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">bottles(n) := for i from n thru 1 step -1 do (
printf(true, "~d bottle~p of beer on the wall~%", i, i),
printf(true, "~d bottle~p of beer~%", i, i),
Line 7,212:
 
=={{header|MAXScript}}==
<syntaxhighlight lang="maxscript">escapeEnable = true
resetMaxFile #noPrompt
viewport.setType #view_top
Line 7,242:
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.
 
<syntaxhighlight lang="maxscript">for i = 99 to 1 by -1 do (print (i as string + (if i == 1 then " bottle" else " bottles") + " of beer on the wall\n" + i as string +\
(if i == 1 then " bottle" else " bottles") + " of beer\nTake one down, pass it around\n" + (i - 1) as string + (if i - 1 == 1 then "\
bottle" else " bottles") + " of beer on the wall\n" + (if i - 1 == 0 then "\nno more beer" else "")))</syntaxhighlight>
 
=={{header|Mercury}}==
<syntaxhighlight lang=Mercury"mercury">
% file: beer.m
% author:
Line 7,312:
=={{header|min}}==
{{works with|min|0.19.3}}
<syntaxhighlight lang="min">(swap quote interpolate puts!) :line
 
(
Line 7,327:
=={{header|MiniScript}}==
Going for the simple/obvious solution here...
<syntaxhighlight lang=MiniScript"miniscript">bottles = function(n)
if n == 0 then return "no bottles"
if n == 1 then return "1 bottle"
Line 7,368:
 
=={{header|MIPS Assembly}}==
<syntaxhighlight lang="mips">
##################################
# 99 bottles of beer on the wall #
Line 7,449:
 
=={{header|Mirah}}==
<syntaxhighlight lang=Mirah"mirah">plural = 's'
99.downto(1) do |i|
puts "#{i} bottle#{plural} of beer on the wall,"
Line 7,465:
 
=={{header|mIRC Scripting Language}}==
<syntaxhighlight lang="mirc">var %x = 99
while (%x) {
echo -ag %x bottles of beer on the wall
Line 7,476:
=={{header|ML/I}}==
=== Simple iterative version ===
<syntaxhighlight lang=ML"ml/Ii">MCSKIP "WITH" NL
"" 99 bottles - simple iterative version
MCSKIP MT,<>
Line 7,498:
 
=== Recursive version ===
<syntaxhighlight lang=ML"ml/Ii">MCSKIP "WITH" NL
"" 99 bottles - recursive version
MCSKIP MT,<>
Line 7,540:
Internal macros define English word replacements for decimal numbers from 0 to 99.
 
<syntaxhighlight lang=ML"ml/Ii">
MCSKIP - WITH - NL
-- The line above defines the comment syntax: -- through to newline is completely deleted.
Line 7,646:
 
=== Output: ===
<syntaxhighlight lang=ML"ml/Ii">
Ninety nine bottles of beer on the wall,
Ninety nine bottles of beer.
Line 7,673:
 
=={{header|mLite}}==
<syntaxhighlight lang="sml">val NL = implode [#"newline"]
 
fun itone 1 = "it"
Line 7,716:
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE b99;
IMPORT InOut;
 
Line 7,741:
 
=={{header|Modula-3}}==
<syntaxhighlight lang="modula3">MODULE Bottles EXPORTS Main;
 
IMPORT IO, Fmt;
Line 7,839:
 
=={{header|MontiLang}}==
<syntaxhighlight lang=MontiLang"montilang">99 VAR i .
 
WHILE i
Line 7,851:
Another way to solve the task that shows some more features of the language.
 
<syntaxhighlight lang=MontiLang"montilang">&DEFINE botellas 99&
 
def rima
Line 7,871:
Infinite loop
 
<syntaxhighlight lang=MontiLang"montilang">99 var botellas .
 
def rima /# n -- n #/
Line 7,897:
 
=={{header|MOO}}==
<syntaxhighlight lang="moo">bottles = 99;
while (bottles > 0)
unit = (bottles == 1 ? "bottle" | "bottles");
Line 7,908:
 
=={{header|MoonScript}}==
<syntaxhighlight lang="moonscript">p = (i) ->
i != 1 and 's' or ''
 
Line 7,924:
=={{header|MUMPS}}==
===Recursive===
<syntaxhighlight lang=MUMPS"mumps">beer(n) If n<1 Write "No bottles of beer on the wall... " Quit
Write !!,n," bottle",$Select(n=1:"",1:"s")," of beer on the wall."
Write !,n," bottle",$Select(n=1:"",1:"s")," of beer."
Line 7,934:
 
===Iterative===
<syntaxhighlight lang=MUMPS"mumps">beer(n) If n<1 Write "No bottles of beer on the wall... " Quit
Write !!,n," bottle",$Select(n=1:"",1:"s")," of beer on the wall."
Write !,n," bottle",$Select(n=1:"",1:"s")," of beer."
Line 7,943:
 
===Brain-damaging===
<syntaxhighlight lang=MUMPS"mumps">bottles
set template1="i_n_""of beer on the wall. ""_i_n_"" of beer. """
set template2="""Take""_n2_""down, pass it around. """
Line 7,963:
It outputs bottles.txt, which contains the lyrics.
 
<syntaxhighlight lang=MyDef"mydef">bottles
$(for:i in 99-1)
$(i) bottles of beer on the wall
Line 7,979:
 
{{works with|All TROFF}}
<syntaxhighlight lang=N"n/t/roff">.nr BS 99 1
.de L1
.ie \\n(BS>1 \{ \
Line 8,002:
 
{{works with|GNU TROFF|1.22.2}}
<syntaxhighlight lang=N"n/t/roff">.nr beers 99 1
.nf
.while \n[beers]>0 \{ \
Line 8,020:
=={{header|Nanoquery}}==
{{trans|Ursa}}
<syntaxhighlight lang="nanoquery">//
// 99 bottles of beer
//
Line 8,045:
 
=={{header|NASL}}==
<syntaxhighlight lang="nasl">bottles = 99;
repeat {
display(bottles, ' bottles of beer on the wall\n');
Line 8,054:
 
=={{header|Neko}}==
<syntaxhighlight lang=ActionScript"actionscript">/**
<doc>
<h3>Rosetta Code, 99 bottles of beer on the wall, in Neko</h3>
Line 8,101:
 
=={{header|Nemerle}}==
<syntaxhighlight lang=Nemerle"nemerle">using System;
using System.Console;
 
Line 8,127:
 
=={{header|NetRexx}}==
<syntaxhighlight lang="netrexx">
beer = "bottles of beer on the wall"
removeOne = "Take one down, pass it arround,"
Line 8,153:
 
=={{header|Nial}}==
<syntaxhighlight lang="nial">line is fork [
0=, 'No more bottles of beer' first,
1=, 'One bottle of beer' first,
Line 8,168:
 
=={{header|Night}}==
<syntaxhighlight lang="night">null bottles(int x) {
if(x == 1) {
print("1 bottle of beer on the wall,\n");
Line 8,190:
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">proc getBottleNumber(n: int): string =
case n
of 0:
Line 8,210:
other:
 
<syntaxhighlight lang="nim">from strutils import format
for i in countdown(99, 1):
Line 8,234:
compact:
 
<syntaxhighlight lang="nim">from strutils import format
 
proc pluralize(a: int): string =
Line 8,248:
organized:
 
<syntaxhighlight lang="nim">from strutils import format
 
var verse = """$1 bottle$3 of beer on the wall
Line 8,263:
 
=={{header|Nix}}==
<syntaxhighlight lang="nix">with builtins;
let
bottle = x: "${toString x} bottle${if (x == 1) then "" else "s"} of beer";
Line 8,278:
=={{header|NS-HUBASIC}}==
With grammatical support for "1 bottle of beer"
<syntaxhighlight lang=NS"ns-HUBASIChubasic">10 WALL$=" ON THE WALL"
20 FOR BOTTLES=99 TO 1 STEP -1
30 BOTTLES$=" BOTTLES OF BEER"
Line 8,291:
 
Without grammatical support for "1 bottle of beer"
<syntaxhighlight lang=NS"ns-HUBASIChubasic">10 BOTTLES$=" BOTTLES OF BEER"
20 WALL$=" ON THE WALL"
30 FOR BOTTLES=99 TO 1 STEP -1
Line 8,301:
 
=={{header|OASYS}}==
<syntaxhighlight lang="oasys_oac">
class player {}
 
Line 8,338:
 
=={{header|Oberon-2}}==
<syntaxhighlight lang="oberon2">MODULE b99;
 
IMPORT Out;
Line 8,364:
 
=={{header|Objeck}}==
<syntaxhighlight lang="objeck">
class Bottles {
function : Main(args : String[]) ~ Nil {
Line 8,379:
 
=={{header|Objective-C}}==
<syntaxhighlight lang="objc">#import <Foundation/Foundation.h>
 
int main()
Line 8,399:
=={{header|OCaml}}==
===For-loop===
<syntaxhighlight lang="ocaml">for n = 99 downto 1 do
Printf.printf "%d bottles of beer on the wall\n" n;
Printf.printf "%d bottles of beer\n" n;
Line 8,409:
Recursive version that handles plurals.
 
<syntaxhighlight lang="ocaml">let verse n =
let
line2 = function
Line 8,438:
Monadic version, expressing actions which evolve the program state and log output. Special cases and grammar rules are handled.
 
<syntaxhighlight lang="ocaml">(* A basic "Writer" monoid with emit *)
module Writer = struct
type 'a t = 'a * string
Line 8,467:
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,482:
 
=={{header|Octave}}==
<syntaxhighlight lang="octave">function bottles(n)
bottle = "bottle";
ofbeer = "of beer";
Line 8,506:
bottles(99);</syntaxhighlight>
=={{header|Odin}}==
<syntaxhighlight lang=Odin"odin">package main
 
import "core:fmt"
Line 8,537:
=={{header|Oforth}}==
 
<syntaxhighlight lang=Oforth"oforth">"bottles of beer on the wall\n" const: B
"bottles of beer\nTake one down, pass it around\n" const: T
Line 8,547:
=={{header|Onyx}}==
 
<syntaxhighlight lang=Onyx"onyx">$Bottles {
dup cvs ` bottle' cat exch 1 ne {`s' cat} if
` of beer' cat
Line 8,580:
 
=={{header|OOC}}==
<syntaxhighlight lang="ooc">
sing_line: func (b: Int, suffix: Bool) {
"#{b > 0 ? "#{b}" : "No more"} bottle#{b == 1 ? "" : "s"}" print()
Line 8,611:
 
=={{header|OpenEdge/Progress}}==
<syntaxhighlight lang=Progress"progress (Openedgeopenedge ABLabl)">DEFINE VARIABLE amountofbottles AS INTEGER NO-UNDO INITIAL 99.
&GLOBAL-DEFINE bbm bottles of beer
&GLOBAL-DEFINE bbs bottle of beer
Line 8,647:
=={{header|Openscad}}==
El código es de Marc Vanlindt (marc@vanlindt.be)
<syntaxhighlight lang="openscad">num_bottles = 99;
s1 = " of beer";
s2 = " on the wall";
Line 8,672:
==="Pure" Order===
This solution uses only Order language constructs to generate and manipulate tokens:
<syntaxhighlight lang="c">#include "order/interpreter.h"
 
ORDER_PP
Line 8,692:
===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:
<syntaxhighlight lang="c">#include "order/interpreter.h"
 
#define GEN_phrase(N_bottles, N_minus_1_bottles) \
Line 8,720:
 
=={{header|Oxygene}}==
<syntaxhighlight lang="oxygene">
namespace ConsoleApplication2;
 
Line 8,760:
=== Constraint Programming ===
Note: In real life, you would never solve a simple iterative task like this with constraint programming. This is just for fun.
<syntaxhighlight lang="oz">declare
%% describe the possible solutions of the beer 'puzzle'
proc {BeerDescription Solution}
Line 8,787:
 
=== Iterative ===
<syntaxhighlight lang="oz">declare
fun {Bottles N}
if N == 1 then "1 bottle"
Line 8,803:
 
=={{header|PARI/GP}}==
<syntaxhighlight lang="parigp">forstep(n=99,3,-1,
print(n" bottles of beer on the wall");
print(n" bottles of beer");
Line 8,816:
 
=={{header|Perl}}==
<syntaxhighlight lang="perl">#!/usr/bin/perl -w
 
my $verse = <<"VERSE";
Line 8,836:
 
Alternatively:
<syntaxhighlight lang="perl">for $n (reverse(0..99))
{
$bottles = sprintf("%s bottle%s of beer on the wall\n",(($n==0)?"No":$n), (($n==1)?"":"s"));
Line 8,844:
 
Correct grammar and nice spacing in modern perl:
<syntaxhighlight lang="perl">use 5.10.0;
 
$num = 99;
Line 8,860:
 
Using perl5 as a DSL factory leveraging $_'s global nature:
<syntaxhighlight lang="perl">
#!/usr/bin/env perl
use strict;
Line 8,879:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">ninetynine</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">99</span> <span style="color: #000080;font-style:italic;">-- (set to 9 for testing)</span>
Line 8,913:
 
=={{header|Phixmonti}}==
<syntaxhighlight lang=Phixmonti"phixmonti">def bottles
dup if
dup 1 == if
Line 8,935:
for verse . endfor</syntaxhighlight>
With syntactic sugar
<syntaxhighlight lang=Phixmonti"phixmonti">include ..\Utilitys.pmt
def bottles
Line 8,961:
{{trans|C}}
 
<syntaxhighlight lang="phl">module bottles;
extern printf;
 
Line 8,978:
 
=={{header|PHP}}==
<syntaxhighlight lang="php"><?php
$plural = 's';
foreach (range(99, 1) as $i) {
Line 8,995:
 
===shorter way===
<syntaxhighlight lang="php"><?php
foreach(range(99,1) as $i) {
$p = ($i>1)?"s":"";
Line 9,011:
 
===Tag syntax===
<syntaxhighlight lang="php"><?php foreach(range(99,1) as $i):?>
<?=$i?> bottle<?=$i==1 ? '' : 's'?> of beer on the wall,
<?=$i?> bottle<?=$i==1 ? '' : 's'?> of beer!
Line 9,023:
 
===modifing way===
<syntaxhighlight lang="php"><?php
$verse = <<<VERSE
100 bottles of beer on the wall,
Line 9,045:
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
<syntaxhighlight lang="php"><?php
for($i=100;$i>0;$i--){
$p2=$i." bottle".(($i>1)?"s":"")." of beer";
Line 9,056:
supports grammar and translations.
 
<syntaxhighlight lang="php"><?php
 
$bottles = 99;
Line 9,076:
Fun with HEREDOC and printf placeholders
 
<syntaxhighlight lang="php"><?php
 
$lyrics = <<<ENDVERSE
Line 9,144:
 
=={{header|Picat}}==
<syntaxhighlight lang=Picat"picat">
beer1(N) =>
Beer = N,
Line 9,176:
 
=={{header|Pike}}==
<syntaxhighlight lang="pike">int main(){
for(int i = 99; i > 0; i--){
write(i + " bottles of beer on the wall, " + i + " bottles of beer.\n");
Line 9,186:
 
alternate version:
<syntaxhighlight lang=Pike"pike">// disclaimer: i prefer gingerale
 
void main()
Line 9,213:
=={{header|PILOT}}==
El código es de Akira KIDA (SDI00379@niftyserve.or.jp)
<syntaxhighlight lang="pilot">C :bottles = 99
 
U : *beers
Line 9,235:
{{works with|Parrot|Tested with 2.4.0}}
 
<syntaxhighlight lang="pir">.sub sounding_smart_is_hard_after_drinking_this_many
.param int b
if b == 1 goto ONE
Line 9,268:
 
=={{header|PlainTeX}}==
<syntaxhighlight lang="tex">\def\ifbeer{\ifnum\number\bottles}
\def\beers{
\par\ifbeer>0 \the\bottles~\else No more \fi
Line 9,293:
 
=={{header|PL/I}}==
<syntaxhighlight lang="pli">bottles: procedure options(main);
nBottles: procedure(n);
declare n fixed;
Line 9,333:
 
=={{header|PL/M}}==
<syntaxhighlight lang="plm">100H: /* CP/M ORIGIN */
 
BDOS: PROCEDURE(F,PARAM); /* CALL CP/M BDOS */
Line 9,405:
=={{header|Pointless}}==
 
<syntaxhighlight lang="pointless">-----------------------------------------------------------
-- Print the lyrics to the song '99 bottles of beer'
 
Line 9,437:
=={{header|Pony}}==
=== Recursive ===
<syntaxhighlight lang="pony">actor Main
let _env: Env
new create(env: Env) =>
Line 9,458:
end</syntaxhighlight>
=== Iterative ===
<syntaxhighlight lang="pony">actor Main
let _env: Env
new create(env: Env) =>
Line 9,478:
 
=={{header|Pop11}}==
<syntaxhighlight lang="pop11">define bootles(n);
while n > 0 do
printf(n, '%p bottles of beer on the wall\n');
Line 9,491:
 
=={{header|PostScript}}==
<syntaxhighlight lang=PostScript"postscript">%!PS
/Helvetica findfont 9 scalefont setfont
 
Line 9,533:
No extra credit.
 
<syntaxhighlight lang=Potion"potion">99 to 1 (i) :
verse = (n) :
(n, " bottles of beer on the wall\n"
Line 9,552:
 
Immediately prints all output to the console.
<syntaxhighlight lang=Processing"processing">for (int i = 99; i > 0; i--) {
print(i + " bottles of beer on the wall\n"
+ i + " bottles of beer\nTake one down, pass it around\n"
Line 9,561:
 
This approach uses Processing's draw loop to display text on the sketch canvas, with a global counter for bottles--draw() is called at the default 60fps, and acts as the for loop. One round of lyrics is displayed at a time, and the counter advances by checking Processing's built-in frameCount. Lyrics may also be advanced manually by clicking the mouse on the canvas.
<syntaxhighlight lang="java">int i = 99;
void setup() {
size(200, 140);
Line 9,583:
==={{header|Processing Python mode}}===
{{trans|Processing}}
<syntaxhighlight lang="python">i = 99
def setup():
size(200, 140)
Line 9,607:
'''Console output'''
 
<syntaxhighlight lang="r">setup <- function() {
stdout$print(bottlesong(99))
}
Line 9,636:
Quite a short, one-line version.
 
<syntaxhighlight lang=Python"python">for i in range(99, 0, -1): b ='bottles of beer'; w = b + ' on the wall'; print(f'{i} {w}, {i} {b}\nTake one down and pass it around, {i - 1} {w}.\n')
</syntaxhighlight>
 
Line 9,667:
Version with correct grammar and correct ending ("no more bottles ..."). The problem that has not been solved is that the number of bottles is written in numbers, not in words. The program is '''PEP8 compliant''' and remains readable even to those unfamiliar with Python.
 
<syntaxhighlight lang=Python"python">#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
Line 9,700:
{{Trans|Haskell}}
{{Works with|Python|3.7+}}
<syntaxhighlight lang="python">'''99 Units of Disposable Asset'''
 
 
Line 9,818:
Inspired by [[99_Bottles_of_Beer#Functional|Functional version]]
 
<syntaxhighlight lang="python">"""
99 Bottles of Beer on the Wall made functional
Line 9,978:
Inspired by the [[99_Bottles_of_Beer#Python_3.2C_functional.2C_pythonic_version|Functional Pythonic Version]]
 
<syntaxhighlight lang="python">"""
Excercise of style. An overkill for the task :-D
 
Line 10,240:
 
=={{header|Q}}==
<syntaxhighlight lang="q">bobw:{[n] {x," bottles of beer on the wall\n",x," bottles of beer\nTake one down, pass it around\n",y," bottles of beer on the wall\n\n"} . string (n;n-1)}
-1 bobw each reverse 1 + til 99</syntaxhighlight>
 
Line 10,247:
'''[NOTE]:''' The code below is an amazing, full-on media event! For a simpler version, click [[99_Bottles_of_Beer/Basic#QB64 | HERE.]]
----
<syntaxhighlight lang=QB64"qb64">SCREEN _NEWIMAGE(800, 600, 32)
CONST BottleSpeed = 3
PLAY "<"
Line 10,364:
===Simple Solution===
 
<syntaxhighlight lang="qore">#!/usr/bin/env qore
 
%enable-all-warnings
Line 10,377:
===Concurrent (Unordered) Solution===
 
<syntaxhighlight lang="qore">#!/usr/bin/env qore
%enable-all-warnings
Line 10,407:
 
=={{header|Quackery}}==
<syntaxhighlight lang="quackery">
[ stack ] is bottles ( --> [ )
 
Line 10,445:
 
=={{header|Quill}}==
<syntaxhighlight lang="quill">bottles := void(int count) {
(count > 0) if {
new_count := count - 1;
Line 10,463:
=={{header|Quite BASIC}}==
With grammatical support for "1 bottle of beer"
<syntaxhighlight lang=Quite"quite BASICbasic">10 let w=" on the wall"
20 for n=99 to 1 step -1
30 let b=" bottles of beer"
Line 10,476:
 
Without grammatical support for "1 bottle of beer"
<syntaxhighlight lang=Quite"quite BASICbasic">10 let b=" bottles of beer"
20 let w=" on the wall"
30 for n=99 to 1 step -1
Line 10,488:
===Simple looping solution===
 
<syntaxhighlight lang="rsplus">#a naive function to sing for N bottles of beer...
 
song = function(bottles){
Line 10,506:
 
===Vector solutions===
<syntaxhighlight lang="rsplus">#only one line!
cat(paste(99:1,ifelse((99:1)!=1," bottles"," bottle")," of beer on the wall\n",99:1,ifelse((99:1)!=1," bottles"," bottle")," of beer\n","Take one down, pass it around\n",98:0,ifelse((98:0)!=1," bottles"," bottle")," of beer on the wall\n\n",sep=""),sep="")
 
Line 10,516:
 
=={{header|Ra}}==
<syntaxhighlight lang=Ra"ra">
class BottlesOfBeer
**Prints the "99 Bottles of Beer" song"**
Line 10,569:
 
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket
(define (sing bottles)
Line 10,585:
=== A Simple Way ===
 
<syntaxhighlight lang=perl6"raku" line>my $b = 99;
 
repeat while --$b {
Line 10,603:
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=perl6"raku" line>for 99...1 -> $bottles {
sing $bottles, :wall;
sing $bottles;
Line 10,625:
 
{{works with|Rakudo|2015.09}}
<syntaxhighlight lang=perl6"raku" line>my @quantities = flat (99 ... 1), 'No more', 99;
my @bottles = flat 'bottles' xx 98, 'bottle', 'bottles' xx 2;
my @actions = flat 'Take one down, pass it around' xx 99,
Line 10,640:
 
=={{header|RapidQ}}==
<syntaxhighlight lang=RapidQ"rapidq">
dim nBott as integer
nBott = 99
Line 10,657:
 
=={{header|Rascal}}==
<syntaxhighlight lang="rascal">
module demo::basic::Bottles
 
Line 10,677:
 
=={{header|Raven}}==
<syntaxhighlight lang="raven">99 0 1 range each as $i
$i 1 = if
"bottle" as $b
Line 10,708:
 
=={{header|REBOL}}==
<syntaxhighlight lang=REBOL"rebol">rebol [
Title: "99 Bottles of Beer"
URL: http://rosettacode.org/wiki/99_Bottles_of_Beer
Line 10,745:
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:
 
<syntaxhighlight lang=REBOL"rebol">for i 99 1 -1 [
x: rejoin [
i b: " bottles of beer" o: " on the wall. " i b
Line 10,757:
Here's a simple 1 line console version:
<syntaxhighlight lang=REBOL"rebol">for i 99 1 -1[print rejoin[i b:" bottles of beer"o:" on the wall. "i b". Take one down, pass it around. "(i - 1)b o"^/"]]</syntaxhighlight>
 
=={{header|Red}}==
<syntaxhighlight lang=Red"red">Red [
Title: "99 Bottles of Beer"
Original-Author: oofoe
Line 10,783:
 
=={{header|Relation}}==
<syntaxhighlight lang=Relation"relation">
program beer(n)
if n>1
Line 10,811:
This is based on the [[Forth]] example.
 
<syntaxhighlight lang=Retro"retro"># 99 Bottles
 
Display the text for the *99 Bottles of Beer* song.
Line 10,842:
=={{header|REXX}}==
Complete with a PSA &nbsp; (<u>P</u>ublic <u>S</u>ervice <u>A</u>nnouncement) &nbsp; comment.
<syntaxhighlight lang="rexx">/*REXX program displays lyrics to the infamous song "99 Bottles of Beer on the Wall". */
parse arg N .; if N=='' | N=="," then N=99 /*allow number of bottles be specified.*/
/* [↓] downward count of beer bottles.*/
Line 10,901:
=={{header|Ring}}==
This is a simple solution
<syntaxhighlight lang="ring">for i = 99 to 0 step -1
switch i
on 0
Line 10,948:
Rockstar solution without special cases for the last 2 verses.
 
<syntaxhighlight lang="rockstar">Love is " bottles of beer on the wall"
Problems are " bottles of beer"
Carol says Take one down, pass it around
Line 10,964:
{{works with|RPGIII|}}
 
<syntaxhighlight lang=RPG"rpg"> H/TITLE 99 Bottles of Beer on the Wall - RPGIII (IBM System/38)
F********************************************************************
F*
Line 11,058:
=={{header|RPL/2}}==
===Simple solution===
<syntaxhighlight lang="rpl/2">BEER
<<
99 do
Line 11,082:
 
===Recursive and multithreaded solution===
<syntaxhighlight lang="rpl/2">BOTTLES
<<
// Child process is started.
Line 11,127:
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">plural = 's'
99.downto(1) do |i|
puts "#{i} bottle#{plural} of beer on the wall,"
Line 11,142:
 
Ruby has variable traces, so we can do
<syntaxhighlight lang="ruby">trace_var :$bottle_num do |val|
$bottles = %Q{#{val == 0 ? 'No more' : val.to_s} bottle#{val == 1 ? '' : 's'}}
end
Line 11,155:
end</syntaxhighlight>
or...
<syntaxhighlight lang="ruby">def bottles(of_beer, ending)
puts "#{of_beer} bottle#{ending} of beer on the wall,"
puts "#{of_beer} bottle#{ending} of beer"
Line 11,171:
end</syntaxhighlight>
or...
<syntaxhighlight lang="ruby">def bottles(beer, wall = false)
"#{beer>0 ? beer : "no more"} bottle#{"s" if beer!=1} of beer#{" on the wall" if wall}"
end
Line 11,187:
 
===Simple solution===
<syntaxhighlight lang="ruby">
99.downto(1) do |bottles|
puts "#{bottles} bottle#{"s" if bottles != 1} of beer on the wall.",
Line 11,199:
 
===Simple Solution===
<syntaxhighlight lang="rust">fn main() {
for n in (0..100).rev() {
match n {
Line 11,219:
 
===Using a trait and impl===
<syntaxhighlight lang="rust">trait Bottles {
fn bottles_of_beer(&self) -> Self;
fn on_the_wall(&self);
Line 11,250:
 
=={{header|S-BASIC}}==
<syntaxhighlight lang="basic">
rem - print lyrics to "99 Bottles of Beer on the Wall"
 
Line 11,297:
 
=={{header|Sather}}==
<syntaxhighlight lang="sather">class MAIN is
main is
s :STR;
Line 11,317:
=={{header|Scheme}}==
 
<syntaxhighlight lang="scheme">
(define (sing)
(define (sing-to-x n)
Line 11,336:
 
=={{header|sed}}==
<syntaxhighlight lang="sed">s/.*/99 bottles of beer on the wall/
h
: b
Line 11,364:
 
=={{header|Seed7}}==
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 11,387:
Below is a straightforward implementation in SenseTalk. A completely fanciful version (which also works!) can be found here: http://www.99-bottles-of-beer.net/language-sensetalk-1794.html
 
<syntaxhighlight lang="sensetalk">
set bottleCount to 99
set bottleCount's format to "Words"
Line 11,403:
</syntaxhighlight>
Output:
<syntaxhighlight lang="sensetalk">
Ninety-Nine bottles of beer on the wall,
Ninety-Nine bottles of beer!
Line 11,428:
 
=={{header|SequenceL}}==
<syntaxhighlight lang="sequencel">import <Utilities/Conversion.sl>;
import <Utilities/Sequence.sl>;
 
Line 11,460:
 
=={{header|Set lang}}==
<syntaxhighlight lang=Set_lang"set_lang">set l 10
set s 32
set m 44
Line 11,559:
 
=={{header|Shiny}}==
<syntaxhighlight lang="shiny">for 99 i:99-a
s: if i > 1 's' end
 
Line 11,575:
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">for i in (100 ^.. 0) {
var bottles = "#{i == 0 ? 'No' : i} bottle#{i == 1 ? '' : 's'}"
var sentence = "#{bottles} of beer on the wall" -> say
Line 11,585:
 
'''Simpler:'''
<syntaxhighlight lang="ruby">for n in (100 ^.. 2) {
say "#{n} bottles of beer on the wall, #{n} bottles of beer!"
say "Take one down, pass it around, #{n - 1} bottle#{n > 2 ? 's' : ''} of beer on the wall.\n"
Line 11,594:
 
=={{header|Simula}}==
<syntaxhighlight lang="simula">COMMENT HTTP://99-BOTTLES-OF-BEER.NET ;
COMMENT AUTHOR: TIM GOODWIN ;
COMMENT DATE: 04/20/05 ;
Line 11,632:
</syntaxhighlight>
'''Simpler:'''
<syntaxhighlight lang="simula">COMMENT http://99-bottles-of-beer.net
author: Jack Leunissen
date: 03/10/07;
Line 11,665:
=={{header|SkookumScript}}==
 
<syntaxhighlight lang="javascript">!bottles: (Integer num) [num.String += if num=1 [" bottle"] else [" bottles"]]
99.to 1
[
Line 11,676:
 
=={{header|Slate}}==
<syntaxhighlight lang="slate">n@(Integer traits) bottleVerse
[| nprinted |
nprinted: n printString ; ' bottle' ; (n > 1 ifTrue: ['s'] ifFalse: ['']) ; ' of beer'.
Line 11,692:
99 bottles.</syntaxhighlight>
=={{header|Slope}}==
<syntaxhighlight lang="scheme">
;; 99 bottles of beer
;;
Line 11,720:
=={{header|Smalltalk}}==
A straightforward approach:
<syntaxhighlight lang="smalltalk">Smalltalk at: #sr put: 0 ; at: #s put: 0 !
sr := Dictionary new.
sr at: 0 put: ' bottle' ;
Line 11,738:
=={{header|SmileBASIC}}==
Pretty comical version. MML tunes based on QB64 version.
<syntaxhighlight lang="smilebasic">DEF NUM(N)
IF N==-1 THEN
RETURN "99"
Line 11,789:
 
=={{header|SNOBOL4}}==
<syntaxhighlight lang="snobol"> x = 99
again output = X " bottles of beer on the wall"
output = X " bottles of beer" ?eq(X,0) :s(zero)
Line 11,802:
{{works with|CSnobol}}
Function version with string composition. Function returns one verse for x bottles. Correctly handles bottle/bottles.
<syntaxhighlight lang=SNOBOL4"snobol4"> define('bottles(x)')
nl = char(13) char(10) ;* Win/DOS, change as needed
s2 = ' of beer'; s3 = ' on the wall'
Line 11,841:
=={{header|Sparkling}}==
 
<syntaxhighlight lang="sparkling">var bottles = 99;
 
do {
Line 11,854:
=={{header|SQL}}==
 
<syntaxhighlight lang=SQL"sql">
select
( 100 - level ) || ' bottle' || case when level != 99 then 's' end || ' of beer on the wall'
Line 11,866:
</syntaxhighlight>
 
<syntaxhighlight lang=SQL"sql">
 
 
Line 11,902:
This Statement does also work with T-SQL, but only up to 32 beers
 
<syntaxhighlight lang=SQL"sql">
CREATE PROCEDURE bottles
@bottle_count int,
Line 11,952:
</syntaxhighlight>
 
<syntaxhighlight lang=SQL"sql">
 
/*These statements work in PostgreSQL (tested in 9.4)*/
Line 11,991:
 
=={{header|Squirrel}}==
<syntaxhighlight lang="squirrel">
function rec(bottles)
{
Line 12,010:
 
=={{header|Standard ML}}==
<syntaxhighlight lang="sml">fun bottles 0 = ()
| bottles x = ( print (Int.toString x ^ " bottles of beer on the wall\n");
print (Int.toString x ^ " bottles of beer\n");
Line 12,018:
)</syntaxhighlight>
The following code outputs the [https://99-bottles-of-beer.net/lyrics.html full lyrics], generating duplicate text blocks only once.
<syntaxhighlight lang="sml">fun capitalize s =
(str o Char.toUpper o String.sub) (s, 0) ^ String.extract (s, 1, NONE)
 
Line 12,050:
 
=={{header|Stata}}==
<syntaxhighlight lang="stata">program drink
local s s
forvalues i=`1'(-1)0 {
Line 12,094:
 
=={{header|Suneido}}==
<syntaxhighlight lang=Suneido"suneido">i = 99
while (i > 0)
{
Line 12,108:
 
=={{header|SuperCollider}}==
<syntaxhighlight lang=SuperCollider"supercollider">// post to the REPL directly
(
(99..0).do { |n|
Line 12,131:
 
=={{header|xTalk}}==
<syntaxhighlight lang="livecode">
function beerMe numberOfBottles
   put "XX bottles of beer on the wall" into verseA
Line 12,144:
</syntaxhighlight>
 
<syntaxhighlight lang="supertalk">
on mouseup
 
Line 12,174:
 
=={{header|Swift}}==
<syntaxhighlight lang="swift">
for i in (1...99).reversed() {
print("\(i) bottles of beer on the wall, \(i) bottles of beer.")
Line 12,184:
=={{header|Symsyn}}==
 
<syntaxhighlight lang="symsyn">
BBW : ' Bottles of beer on the wall '
TOD : 'Take one down and pass it around '
Line 12,207:
 
=={{header|Tailspin}}==
<syntaxhighlight lang="tailspin">
templates sayBottleCount
when <=1> do
Line 12,253:
 
=={{header|TIScript}}==
<syntaxhighlight lang="javascript">
var beer = 99;
while (beer > 0)
Line 12,266:
=={{header|TMG}}==
Unix TMG:
<syntaxhighlight lang=UnixTMG"unixtmg">loop: parse(line1) [--n] parse(line2) [n>=1?]\loop;
line1: beer = { 1 < on the wall, > 1 <.> * };
line2: beer = { <If one of those bottles should happen to fall, > 1 < on the wall.> * };
Line 12,275:
 
=={{header|TorqueScript}}==
<syntaxhighlight lang=TorqueScript"torquescript">
for(%i = 99; %i >= 0; %i--)
{
Line 12,286:
 
=={{header|TUSCRIPT}}==
<syntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
LOOP bottle=1,100
Line 12,308:
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.
 
<syntaxhighlight lang="txr">@(next :list @(mapcar* (fun tostring) (range 99 -1 -1)))
@(collect)
@number
Line 12,343:
To make the song repeat indefinitely, change the first line to:
 
<syntaxhighlight lang="txr">@(next :list @(mapcar* (fun tostring) (repeat (range 99 0 -1))))</syntaxhighlight>
 
Now it's processing an infinite lazy lists consisting of
Line 12,349:
 
=={{header|TypeScript}}==
<syntaxhighlight lang="javascript">function beerSong(){
function nbottles(howMany:number){
return `${howMany?howMany:'no'} bottle${howMany!=1?'s':''}`;
Line 12,370:
=={{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,404:
0052 PRINT "Go to the store and buy some more...99 bottles of beer."</syntaxhighlight>
And a more structured version.
<syntaxhighlight lang="text">for n=99 to 2 step -1
print n;" bottles of beer on the wall, ";n;" bottles of beer!"
print "Take one down, pass it around, ";n-1;" bottle";
Line 12,426:
 
=={{header|Ursa}}==
<syntaxhighlight lang="text">
#
# 99 bottles of beer
Line 12,454:
 
=={{header|Ursala}}==
<syntaxhighlight lang=Ursala"ursala">#import nat
 
# each function takes a natural number to a block of text
Line 12,483:
 
=={{header|UTFool}}==
<syntaxhighlight lang=UTFool"utfool">
···
http://rosettacode.org/wiki/99_Bottles_of_Beer
Line 12,505:
 
=={{header|V}}==
<syntaxhighlight lang="v">[bottles
[newline '' puts].
[beer
Line 12,519:
 
=={{header|Vala}}==
<syntaxhighlight lang="vala">void main() {
uint bottles = 99;
do {
Line 12,548:
Most of the keywords in Vedit macro language have both short and long format.
Normally, long format is used here in Rosetta Code for clarity, so here is an example using the short keywords.
<syntaxhighlight lang="vedit">RS(1, " 99")
RS(2, " bottles of beer")
RS(3, " on the wall")
Line 12,565:
 
=={{header|Verbexx}}==
<syntaxhighlight lang=Verbexx"verbexx">fb @FN [x] { @IF (x == 1) then:{ 'bottle } else:{ 'bottles } };
 
@LOOP init:{@VAR n = 99} until:(n == 0)
Line 12,578:
 
=={{header|Verilog}}==
<syntaxhighlight lang=Verilog"verilog">
module beer;
integer i;
Line 12,604:
=={{header|Viua VM assembly}}==
 
<syntaxhighlight lang="asm">
.function: bottles_of_beer_text/1
.name: %iota number_of_bottles
Line 12,719:
Fails the task definition for more song, includes the no beer verse.
 
<syntaxhighlight lang="go">// 99 bottles of V
module main
 
Line 12,756:
 
=={{header|Vox}}==
<syntaxhighlight lang="vox">
// translated from <http://rosettacode.org/wiki/99_Bottles_of_Beer#JavaScript>
 
Line 12,773:
 
=={{header|VTL-2}}==
<syntaxhighlight lang=VTL2"vtl2">10 B=99
20 #=200
30 ?=" of beer on the wall,"
Line 12,807:
 
=={{header|Wortel}}==
<syntaxhighlight lang="wortel">!console.log @unlines ~!* 99..0 !? {
0 "0 bottles of beer on the wall\n0 bottles of beer\nbetter go to the store and buy some more."
"{@x} bottle{@?@x{1 @e 's}} of beer on the wall\n{@x} bottle{@?@x{1 @e 's}} of beer\nTake one down, pass it around"
Line 12,813:
 
=={{header|Wrapl}}==
<syntaxhighlight lang="wrapl">MOD Bottles;
 
IMP IO.Terminal USE Out;
Line 12,833:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascript">for (i in 99...0) {
System.print("%(i) bottles of beer on the wall,")
System.print("%(i) bottles of beer,")
Line 12,841:
 
=={{header|X10}}==
<syntaxhighlight lang=X10"x10">public class NinetyNineBottles{
public static def main(args: Rail[String]){
val beerSong: NinetyNineBottles = NinetyNineBottles.make(99);
Line 12,913:
 
=={{header|XBS}}==
<syntaxhighlight lang=XBS"xbs">set Bottles = 99;
while (Bottles > 0){
log(Bottles+" bottles of beer on the wall,");
Line 12,927:
=={{header|Xojo}}==
Place the following in the '''Run''' event handler of a Console application:
<syntaxhighlight lang="vb">Dim bottles As Integer = 99
While bottles > 0
Print(bottles.ToText + " bottles of beer on the wall,")
Line 12,941:
A solution written in pure XPath 3.0 (using XSLT as a host language).
 
<syntaxhighlight lang="xml"><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:output method="text"/>
<xsl:template match="/">
Line 12,958:
 
=={{header|XPL0}}==
<syntaxhighlight lang=XPL0"xpl0">code IntOut=11, Text=12;
int B;
[B:= 99;
Line 12,975:
To run, transform any document with this stylesheet (the input document is ignored).
 
<syntaxhighlight lang="xml"><?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="utf-8"/>
Line 13,061:
* use of text value templates (using "{ XPath code }") [first available XSLT 3, see https://www.w3.org/TR/xslt-30/#text-value-templates]
 
<syntaxhighlight lang="xml"><?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="3.0">
Line 13,083:
 
=={{header|Yabasic}}==
<syntaxhighlight lang=Yabasic"yabasic">sub bottle$(i)
if i=0 return "no more bottles of beer"
if i=1 return "1 bottle of beer"
Line 13,095:
 
=={{header|Yacas}}==
<syntaxhighlight lang=Yacas"yacas">
For (b := 99, b > 0, b--)
Echo({b, "bottle(s) of beer on the wall," : Nl(),
Line 13,107:
 
=== Looped version ===
<syntaxhighlight lang="yorick">bottles = 99;
while(bottles) {
write, format=" %d bottles of beer on the wall\n", bottles;
Line 13,116:
 
=== Vectorized version ===
<syntaxhighlight lang="yorick">song = "%d bottles of beer on the wall\n";
song += "%d bottles of beer\n";
song += "Take one down, pass it around\n";
Line 13,127:
 
=={{header|zkl}}==
<syntaxhighlight lang="zkl">[99..0,-1].pump(fcn(n){
println(beers(n), " on the wall, ", beers(n).toLower(), ".\n",
n==0 and ("Go to the store and buy some more, 99 bottles of beer") or
10,339

edits