FizzBuzz: Difference between revisions

Content deleted Content added
Wodan58 (talk | contribs)
Thundergnat (talk | contribs)
m syntax highlighting fixup automation
Line 25: Line 25:
{{trans|Python3: Simple}}
{{trans|Python3: Simple}}


<lang 11l>L(i) 1..100
<syntaxhighlight lang="11l">L(i) 1..100
I i % 15 == 0
I i % 15 == 0
print(‘FizzBuzz’)
print(‘FizzBuzz’)
Line 33: Line 33:
print(‘Buzz’)
print(‘Buzz’)
E
E
print(i)</lang>
print(i)</syntaxhighlight>


=={{header|360 Assembly}}==
=={{header|360 Assembly}}==
Line 51: Line 51:


=={{header|8th}}==
=={{header|8th}}==
<lang forth>
<syntaxhighlight lang="forth">
with: n
with: n


Line 77: Line 77:
' fizzbuzz 1 100 loop
' fizzbuzz 1 100 loop
cr bye
cr bye
</syntaxhighlight>
</lang>


=={{header|AArch64 Assembly}}==
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program FizzBuzz64.s */
/* program FizzBuzz64.s */
Line 176: Line 176:
/* for this file see task include a file in language AArch64 assembly */
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>


=={{header|ABAP}}==
=={{header|ABAP}}==
===Impure Functional 1===
===Impure Functional 1===
{{works with|ABAP|7.4 SP05 or Above only}}
{{works with|ABAP|7.4 SP05 or Above only}}
<lang ABAP>DATA: tab TYPE TABLE OF string.
<syntaxhighlight lang="abap">DATA: tab TYPE TABLE OF string.


tab = VALUE #(
tab = VALUE #(
Line 193: Line 193:


cl_demo_output=>write( tab ).
cl_demo_output=>write( tab ).
cl_demo_output=>display( ).</lang>
cl_demo_output=>display( ).</syntaxhighlight>


===Impure Functional 2===
===Impure Functional 2===
{{works with|ABAP|7.4 SP05 or Above only}}
{{works with|ABAP|7.4 SP05 or Above only}}
<lang ABAP>cl_demo_output=>display( value stringtab( for i = 1 until i > 100
<syntaxhighlight lang="abap">cl_demo_output=>display( value stringtab( for i = 1 until i > 100
let fizz = cond #( when i mod 3 = 0 then |fizz| else space )
let fizz = cond #( when i mod 3 = 0 then |fizz| else space )
buzz = cond #( when i mod 5 = 0 then |buzz| else space )
buzz = cond #( when i mod 5 = 0 then |buzz| else space )
fb = |{ fizz }{ buzz }| in
fb = |{ fizz }{ buzz }| in
( switch #( fb when space then i else fb ) ) ) ).</lang>
( switch #( fb when space then i else fb ) ) ) ).</syntaxhighlight>


=={{header|ACL2}}==
=={{header|ACL2}}==
<lang Lisp>(defun fizzbuzz-r (i)
<syntaxhighlight lang="lisp">(defun fizzbuzz-r (i)
(declare (xargs :measure (nfix (- 100 i))))
(declare (xargs :measure (nfix (- 100 i))))
(prog2$
(prog2$
Line 215: Line 215:
(fizzbuzz-r (1+ i)))))
(fizzbuzz-r (1+ i)))))


(defun fizzbuzz () (fizzbuzz-r 1))</lang>
(defun fizzbuzz () (fizzbuzz-r 1))</syntaxhighlight>


=={{header|Action!}}==
=={{header|Action!}}==
<lang Action!>PROC Main()
<syntaxhighlight lang="action!">PROC Main()
BYTE i,d3,d5
BYTE i,d3,d5


Line 239: Line 239:
IF d5=5 THEN d5=0 FI
IF d5=5 THEN d5=0 FI
OD
OD
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/FizzBuzz.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/FizzBuzz.png Screenshot from Atari 8-bit computer]
Line 252: Line 252:
=={{header|ActionScript}}==
=={{header|ActionScript}}==
The [[ActionScript]] solution works just like the [[FizzBuzz#JavaScript|JavaScript]] solution (they share the [[ECMAScript]] specification). The difference is that ActionScript has the ''trace'' command to write out to a console.
The [[ActionScript]] solution works just like the [[FizzBuzz#JavaScript|JavaScript]] solution (they share the [[ECMAScript]] specification). The difference is that ActionScript has the ''trace'' command to write out to a console.
<lang actionscript>for (var i:int = 1; i <= 100; i++) {
<syntaxhighlight lang="actionscript">for (var i:int = 1; i <= 100; i++) {
if (i % 15 == 0)
if (i % 15 == 0)
trace('FizzBuzz');
trace('FizzBuzz');
Line 261: Line 261:
else
else
trace(i);
trace(i);
}</lang>
}</syntaxhighlight>


=={{header|Ada}}==
=={{header|Ada}}==
<lang ada>with Ada.Text_IO; use Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
procedure Fizzbuzz is
procedure Fizzbuzz is
Line 279: Line 279:
end if;
end if;
end loop;
end loop;
end Fizzbuzz;</lang>
end Fizzbuzz;</syntaxhighlight>


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
<lang algol68>main:(
<syntaxhighlight lang="algol68">main:(
FOR i TO 100 DO
FOR i TO 100 DO
printf(($gl$,
printf(($gl$,
Line 296: Line 296:
))
))
OD
OD
)</lang>
)</syntaxhighlight>
or simply:
or simply:
<lang algol68>FOR i TO 100 DO print(((i%*15=0|"FizzBuzz"|:i%*3=0|"Fizz"|:i%*5=0|"Buzz"|i),new line)) OD</lang>
<syntaxhighlight lang="algol68">FOR i TO 100 DO print(((i%*15=0|"FizzBuzz"|:i%*3=0|"Fizz"|:i%*5=0|"Buzz"|i),new line)) OD</syntaxhighlight>


=={{header|ALGOL-M}}==
=={{header|ALGOL-M}}==
<lang algolm>BEGIN
<syntaxhighlight lang="algolm">BEGIN


INTEGER FUNCTION DIVBY(N, D);
INTEGER FUNCTION DIVBY(N, D);
Line 323: Line 323:
END;
END;


END</lang>
END</syntaxhighlight>


=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
<lang algolw>
<syntaxhighlight lang="algolw">
begin
begin
i_w := 1; % set integers to print in minimum space %
i_w := 1; % set integers to print in minimum space %
Line 335: Line 335:
else write( i )
else write( i )
end for_i
end for_i
end.</lang>
end.</syntaxhighlight>


=={{header|AntLang}}==
=={{header|AntLang}}==
<lang AntLang>n:{1+ x}map range[100]
<syntaxhighlight lang="antlang">n:{1+ x}map range[100]
s:{a:0eq x mod 3;b:0eq x mod 5;concat apply{1elem x}map{0elem x}hfilter seq[1- max[a;b];a;b]merge seq[str[x];"Fizz";"Buzz"]}map n
s:{a:0eq x mod 3;b:0eq x mod 5;concat apply{1elem x}map{0elem x}hfilter seq[1- max[a;b];a;b]merge seq[str[x];"Fizz";"Buzz"]}map n
echo map s</lang>
echo map s</syntaxhighlight>


=={{header|APEX}}==
=={{header|APEX}}==
<syntaxhighlight lang="apex">
<lang Apex>
for(integer i=1; i <= 100; i++){
for(integer i=1; i <= 100; i++){
String output = '';
String output = '';
Line 354: Line 354:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|APL}}==
=={{header|APL}}==
<lang apl>⎕IO←0
<syntaxhighlight lang="apl">⎕IO←0
(L,'Fizz' 'Buzz' 'FizzBuzz')[¯1+(L×W=0)+W←(100×~0=W)+W←⊃+/1 2×0=3 5|⊂L←1+⍳100]
(L,'Fizz' 'Buzz' 'FizzBuzz')[¯1+(L×W=0)+W←(100×~0=W)+W←⊃+/1 2×0=3 5|⊂L←1+⍳100]
</syntaxhighlight>
</lang>




Slightly different approach that makes use of the Decode function (⊥):
Slightly different approach that makes use of the Decode function (⊥):
<lang apl>
<syntaxhighlight lang="apl">
A[I]←1+I←(0⍷A)/⍳⍴A←('FIZZBUZZ' 'FIZZ’ 'BUZZ' 0)[2⊥¨×(⊂3 5)|¨1+⍳100]
A[I]←1+I←(0⍷A)/⍳⍴A←('FIZZBUZZ' 'FIZZ’ 'BUZZ' 0)[2⊥¨×(⊂3 5)|¨1+⍳100]
</syntaxhighlight>
</lang>


The idea is to first calculate the residues for all numbers 1..100 after
The idea is to first calculate the residues for all numbers 1..100 after
Line 387: Line 387:
Here's a Dyalog-specific solution taking advantage of its anonymous function extension:
Here's a Dyalog-specific solution taking advantage of its anonymous function extension:


<lang apl>{ ⍵ 'Fizz' 'Buzz' 'FizzBuzz'[ +/1 2×0=3 5|⍵] }¨1+⍳100</lang>
<syntaxhighlight lang="apl">{ ⍵ 'Fizz' 'Buzz' 'FizzBuzz'[ +/1 2×0=3 5|⍵] }¨1+⍳100</syntaxhighlight>


A slightly different version that works both in Dyalog and GNU APL -- credit to Aniket Bhattacharyea, posted on codeburst.io (https://codeburst.io/fizzbuzz-in-apl-a193d1954b4b):
A slightly different version that works both in Dyalog and GNU APL -- credit to Aniket Bhattacharyea, posted on codeburst.io (https://codeburst.io/fizzbuzz-in-apl-a193d1954b4b):


<lang apl>{(‘FizzBuzz’ ‘Fizz’ ‘Buzz’,⍵)[(0=15 3 5|⍵)⍳1]}¨⍳100</lang>
<syntaxhighlight lang="apl">{(‘FizzBuzz’ ‘Fizz’ ‘Buzz’,⍵)[(0=15 3 5|⍵)⍳1]}¨⍳100</syntaxhighlight>


Yet another solution, excessively commented:
Yet another solution, excessively commented:
Line 397: Line 397:
{{works with|GNU_APL}} (and Dyalog, with [http://course.dyalog.com/autumn2021/Quirks/ ⎕ML ← 2])
{{works with|GNU_APL}} (and Dyalog, with [http://course.dyalog.com/autumn2021/Quirks/ ⎕ML ← 2])


<lang apl> ∇ sv ← fizzbuzz n; t;d
<syntaxhighlight lang="apl"> ∇ sv ← fizzbuzz n; t;d
[1] ⍝⍝ Solve the popular 'fizzbuzz' problem in APL.
[1] ⍝⍝ Solve the popular 'fizzbuzz' problem in APL.
[2] ⍝⍝ \param n - highest number to compute (≥0)
[2] ⍝⍝ \param n - highest number to compute (≥0)
Line 436: Line 436:
[37] ⍝⍝ ⎕ ← ,fizzbuzz 15
[37] ⍝⍝ ⎕ ← ,fizzbuzz 15
[38] ⍝ 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
[38] ⍝ 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
∇</lang>
∇</syntaxhighlight>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
===Procedural===
===Procedural===
<lang AppleScript>property outputText: ""
<syntaxhighlight lang="applescript">property outputText: ""
repeat with i from 1 to 100
repeat with i from 1 to 100
if i mod 15 = 0 then
if i mod 15 = 0 then
Line 453: Line 453:
set outputText to outputText & linefeed
set outputText to outputText & linefeed
end repeat
end repeat
outputText</lang>
outputText</syntaxhighlight>
----
----
If this were a useful task requiring a degree of efficiency, it would be better to replace the cumulative text concatenations with additions to a fast-to-access list and coerce this list to text in one go at the end. Less critically, the <tt>(i mod … = 0)</tt> tests could be nested to reduce the number of these performed from 261 to 200:
If this were a useful task requiring a degree of efficiency, it would be better to replace the cumulative text concatenations with additions to a fast-to-access list and coerce this list to text in one go at the end. Less critically, the <tt>(i mod … = 0)</tt> tests could be nested to reduce the number of these performed from 261 to 200:


<lang applescript>on fizzBuzz(n)
<syntaxhighlight lang="applescript">on fizzBuzz(n)
script o
script o
property output : {}
property output : {}
Line 484: Line 484:
end fizzBuzz
end fizzBuzz


fizzBuzz(100)</lang>
fizzBuzz(100)</syntaxhighlight>


Another alternative would be simply to fill the list with numbers and then go through it again three times overwriting the relevant slots with the appropriate words:
Another alternative would be simply to fill the list with numbers and then go through it again three times overwriting the relevant slots with the appropriate words:


<lang applescript>on fizzBuzz(n)
<syntaxhighlight lang="applescript">on fizzBuzz(n)
script o
script o
property output : {}
property output : {}
Line 511: Line 511:
end fizzBuzz
end fizzBuzz


fizzBuzz(100)</lang>
fizzBuzz(100)</syntaxhighlight>


With the number of numbers raised from 100 to 10,000, the two scripts inserted here take around 0.051 seconds to execute on my current machine, the original AppleScript above around 0.25 seconds, and the one below (originally described as "functional composition") 3.52 seconds.
With the number of numbers raised from 100 to 10,000, the two scripts inserted here take around 0.051 seconds to execute on my current machine, the original AppleScript above around 0.25 seconds, and the one below (originally described as "functional composition") 3.52 seconds.
Line 517: Line 517:
===Functional===
===Functional===
For simplicity, and more efficient use of the scripter's time:
For simplicity, and more efficient use of the scripter's time:
<lang AppleScript>------------------------- FIZZBUZZ -------------------------
<syntaxhighlight lang="applescript">------------------------- FIZZBUZZ -------------------------


-- fizz :: Int -> Bool
-- fizz :: Int -> Bool
Line 610: Line 610:
end script
end script
end if
end if
end mReturn</lang>
end mReturn</syntaxhighlight>


=={{header|Applesoft BASIC}}==
=={{header|Applesoft BASIC}}==
Line 616: Line 616:


=={{header|Arbre}}==
=={{header|Arbre}}==
<lang Arbre>fizzbuzz():
<syntaxhighlight lang="arbre">fizzbuzz():
for x in [1..100]
for x in [1..100]
if x%5==0 and x%3==0
if x%5==0 and x%3==0
Line 630: Line 630:


main():
main():
fizzbuzz() -> io</lang>
fizzbuzz() -> io</syntaxhighlight>


=={{header|Arc}}==
=={{header|Arc}}==
===Arc 3.1 Base===
===Arc 3.1 Base===
<lang lisp>(for n 1 100
<syntaxhighlight lang="lisp">(for n 1 100
(prn:if
(prn:if
(multiple n 15) 'FizzBuzz
(multiple n 15) 'FizzBuzz
(multiple n 5) 'Buzz
(multiple n 5) 'Buzz
(multiple n 3) 'Fizz
(multiple n 3) 'Fizz
n))</lang>
n))</syntaxhighlight>
<lang lisp>(for n 1 100
<syntaxhighlight lang="lisp">(for n 1 100
(prn:check (string (when (multiple n 3) 'Fizz)
(prn:check (string (when (multiple n 3) 'Fizz)
(when (multiple n 5) 'Buzz))
(when (multiple n 5) 'Buzz))
~empty n)) ; check created string not empty, else return n</lang>
~empty n)) ; check created string not empty, else return n</syntaxhighlight>


===Waterhouse Arc===
===Waterhouse Arc===
<lang lisp>(for n 1 100
<syntaxhighlight lang="lisp">(for n 1 100
(prn:case (gcd n 15)
(prn:case (gcd n 15)
1 n
1 n
3 'Fizz
3 'Fizz
5 'Buzz
5 'Buzz
'FizzBuzz))</lang>
'FizzBuzz))</syntaxhighlight>


=={{header|ARM Assembly}}==
=={{header|ARM Assembly}}==
<syntaxhighlight lang="arm_assembly">
<lang ARM_Assembly>
/ * linux GAS */
/ * linux GAS */


Line 774: Line 774:
mov r0, r2
mov r0, r2
mov pc, lr
mov pc, lr
</syntaxhighlight>
</lang>


=={{header|Arturo}}==
=={{header|Arturo}}==
<lang rebol>loop 1..100 [x][
<syntaxhighlight lang="rebol">loop 1..100 [x][
case []
case []
when? [0=x%15] -> print "FizzBuzz"
when? [0=x%15] -> print "FizzBuzz"
Line 783: Line 783:
when? [0=x%5] -> print "Buzz"
when? [0=x%5] -> print "Buzz"
else -> print x
else -> print x
]</lang>
]</syntaxhighlight>
{{out}}
{{out}}
<pre>1
<pre>1
Line 893: Line 893:


=={{header|Asymptote}}==
=={{header|Asymptote}}==
<lang Asymptote>for(int number = 1; number <= 100; ++number) {
<syntaxhighlight lang="asymptote">for(int number = 1; number <= 100; ++number) {
if (number % 15 == 0) {
if (number % 15 == 0) {
write("FizzBuzz");
write("FizzBuzz");
Line 907: Line 907:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|ATS}}==
=={{header|ATS}}==
<lang ats>#include "share/atspre_staload.hats"
<syntaxhighlight lang="ats">#include "share/atspre_staload.hats"


implement main0() = loop(1, 100) where {
implement main0() = loop(1, 100) where {
Line 927: Line 927:
loop(from+1, to)
loop(from+1, to)
end
end
}</lang>
}</syntaxhighlight>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
{{AutoHotkey case}}
{{AutoHotkey case}}
<lang AutoHotkey>Loop, 100
<syntaxhighlight lang="autohotkey">Loop, 100
{
{
If (Mod(A_Index, 15) = 0)
If (Mod(A_Index, 15) = 0)
Line 944: Line 944:
FileDelete, output.txt
FileDelete, output.txt
FileAppend, %output%, output.txt
FileAppend, %output%, output.txt
Run, cmd /k type output.txt</lang>
Run, cmd /k type output.txt</syntaxhighlight>
A short example with cascading ternary operators and graphical output. Press Esc to close the window.
A short example with cascading ternary operators and graphical output. Press Esc to close the window.
<lang AutoHotkey>Gui, Add, Edit, r20
<syntaxhighlight lang="autohotkey">Gui, Add, Edit, r20
Gui,Show
Gui,Show
Loop, 100
Loop, 100
Line 952: Line 952:
Return
Return
Esc::
Esc::
ExitApp</lang>
ExitApp</syntaxhighlight>


=={{header|AutoIt}}==
=={{header|AutoIt}}==
===Example1===
===Example1===
Output via MsgBox():
Output via MsgBox():
<lang AutoIt>For $i = 1 To 100
<syntaxhighlight lang="autoit">For $i = 1 To 100
If Mod($i, 15) = 0 Then
If Mod($i, 15) = 0 Then
MsgBox(0, "FizzBuzz", "FizzBuzz")
MsgBox(0, "FizzBuzz", "FizzBuzz")
Line 967: Line 967:
MsgBox(0, "FizzBuzz", $i)
MsgBox(0, "FizzBuzz", $i)
EndIf
EndIf
Next</lang>
Next</syntaxhighlight>


===Example2===
===Example2===
Output via console, logfile and/or messagebox:
Output via console, logfile and/or messagebox:
<lang AutoIt>#include <Constants.au3>
<syntaxhighlight lang="autoit">#include <Constants.au3>


; uncomment how you want to do the output
; uncomment how you want to do the output
Line 995: Line 995:
EndIf
EndIf
Next
Next
Out("# Done.")</lang>
Out("# Done.")</syntaxhighlight>


=={{header|Avail}}==
=={{header|Avail}}==
<lang Avail>For each i from 1 to 100 do [
<syntaxhighlight lang="avail">For each i from 1 to 100 do [
Print:
Print:
if i mod 15 = 0 then ["FizzBuzz"]
if i mod 15 = 0 then ["FizzBuzz"]
Line 1,005: Line 1,005:
else [“i”]
else [“i”]
++ "\n";
++ "\n";
];</lang>
];</syntaxhighlight>


=={{header|AWK}}==
=={{header|AWK}}==
Line 1,011: Line 1,011:


=={{header|Axe}}==
=={{header|Axe}}==
<lang axe>For(I,1,100)
<syntaxhighlight lang="axe">For(I,1,100)
!If I^3??I^5
!If I^3??I^5
Disp "FIZZBUZZ",i
Disp "FIZZBUZZ",i
Line 1,023: Line 1,023:
.Pause to allow the user to actually read the output
.Pause to allow the user to actually read the output
Pause 1000
Pause 1000
End</lang>
End</syntaxhighlight>


=={{header|Babel}}==
=={{header|Babel}}==
<lang babel>main:
<syntaxhighlight lang="babel">main:
{ { iter 1 + dup
{ { iter 1 + dup
Line 1,047: Line 1,047:
"\n" << }
"\n" << }


100 times }</lang>
100 times }</syntaxhighlight>


=={{header|BaCon}}==
=={{header|BaCon}}==
Line 1,054: Line 1,054:
=={{header|bash}}==
=={{header|bash}}==
Any bash hacker would do this as a one liner at the shell, so...
Any bash hacker would do this as a one liner at the shell, so...
<lang bash>for n in {1..100}; do ((( n % 15 == 0 )) && echo 'FizzBuzz') || ((( n % 5 == 0 )) && echo 'Buzz') || ((( n % 3 == 0 )) && echo 'Fizz') || echo $n; done</lang>
<syntaxhighlight lang="bash">for n in {1..100}; do ((( n % 15 == 0 )) && echo 'FizzBuzz') || ((( n % 5 == 0 )) && echo 'Buzz') || ((( n % 3 == 0 )) && echo 'Fizz') || echo $n; done</syntaxhighlight>
For the sake of readability...
For the sake of readability...
<lang bash>for n in {1..100}; do
<syntaxhighlight lang="bash">for n in {1..100}; do
((( n % 15 == 0 )) && echo 'FizzBuzz') ||
((( n % 15 == 0 )) && echo 'FizzBuzz') ||
((( n % 5 == 0 )) && echo 'Buzz') ||
((( n % 5 == 0 )) && echo 'Buzz') ||
((( n % 3 == 0 )) && echo 'Fizz') ||
((( n % 3 == 0 )) && echo 'Fizz') ||
echo $n;
echo $n;
done</lang>
done</syntaxhighlight>
Here's a very concise approach, with only 75 characters total.
Here's a very concise approach, with only 75 characters total.
Unfortunately it relies on aspects of Bash which are rarely used.
Unfortunately it relies on aspects of Bash which are rarely used.
<lang bash>for i in {1..100};do((i%3))&&x=||x=Fizz;((i%5))||x+=Buzz;echo ${x:-$i};done</lang>
<syntaxhighlight lang="bash">for i in {1..100};do((i%3))&&x=||x=Fizz;((i%5))||x+=Buzz;echo ${x:-$i};done</syntaxhighlight>
Here's the concise approach again, this time separated into multiple lines.
Here's the concise approach again, this time separated into multiple lines.
<lang bash># FizzBuzz in Bash. A concise version, but with verbose comments.
<syntaxhighlight lang="bash"># FizzBuzz in Bash. A concise version, but with verbose comments.
for i in {1..100} # Use i to loop from "1" to "100", inclusive.
for i in {1..100} # Use i to loop from "1" to "100", inclusive.
do ((i % 3)) && # If i is not divisible by 3...
do ((i % 3)) && # If i is not divisible by 3...
Line 1,074: Line 1,074:
x+=Buzz # ...Otherwise, append (not set) the string "Buzz" to x.
x+=Buzz # ...Otherwise, append (not set) the string "Buzz" to x.
echo ${x:-$i} # Print x unless it is blanked out. Otherwise, print i.
echo ${x:-$i} # Print x unless it is blanked out. Otherwise, print i.
done</lang>
done</syntaxhighlight>
It's a bit silly to optimize such a small & fast program,
It's a bit silly to optimize such a small & fast program,
but for the sake of algorithm analysis it's worth noting that
but for the sake of algorithm analysis it's worth noting that
Line 1,098: Line 1,098:
FOR /L version:
FOR /L version:


<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
for /L %%i in (1,1,100) do call :tester %%i
for /L %%i in (1,1,100) do call :tester %%i
goto :eof
goto :eof
Line 1,122: Line 1,122:
:NotFizz
:NotFizz
echo %1
echo %1
</syntaxhighlight>
</lang>


Loop version:
Loop version:


<lang dos>@echo off
<syntaxhighlight lang="dos">@echo off
set n=1
set n=1


Line 1,154: Line 1,154:


:NotFizz
:NotFizz
echo %1</lang>
echo %1</syntaxhighlight>


FOR /L with a block instead of very-high-overhead subroutine call:
FOR /L with a block instead of very-high-overhead subroutine call:


<lang dos>@echo off & setlocal enabledelayedexpansion
<syntaxhighlight lang="dos">@echo off & setlocal enabledelayedexpansion
for /l %%i in (1,1,100) do (
for /l %%i in (1,1,100) do (
set /a m5=%%i %% 5
set /a m5=%%i %% 5
Line 1,167: Line 1,167:
if "!s!"=="" set s=%%i
if "!s!"=="" set s=%%i
echo !s!
echo !s!
)</lang>
)</syntaxhighlight>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
Line 1,175: Line 1,175:
This solution never uses <tt>else</tt>, because bc has no <tt>else</tt> keyword (but some implementations add <tt>else</tt> as an extension).
This solution never uses <tt>else</tt>, because bc has no <tt>else</tt> keyword (but some implementations add <tt>else</tt> as an extension).


<lang bc>for (i = 1; i <= 100; i++) {
<syntaxhighlight lang="bc">for (i = 1; i <= 100; i++) {
w = 0
w = 0
if (i % 3 == 0) { "Fizz"; w = 1; }
if (i % 3 == 0) { "Fizz"; w = 1; }
Line 1,183: Line 1,183:
"
"
}
}
quit</lang>
quit</syntaxhighlight>


=={{header|BCPL}}==
=={{header|BCPL}}==
<lang BCPL>GET "libhdr"
<syntaxhighlight lang="bcpl">GET "libhdr"


LET start() BE $(
LET start() BE $(
Line 1,204: Line 1,204:
$)
$)
$)
$)
</syntaxhighlight>
</lang>


=={{header|beeswax}}==
=={{header|beeswax}}==
Line 1,212: Line 1,212:
“Ordinary” FizzBuzz solution:
“Ordinary” FizzBuzz solution:


<lang beeswax> > q
<syntaxhighlight lang="beeswax"> > q
>@F5~%"d@F{ > @F q
>@F5~%"d@F{ > @F q
_1>F3~%'d`Fizz`@F5~%'d >`Buzz`@FNp
_1>F3~%'d`Fizz`@F5~%'d >`Buzz`@FNp
;bL@~.~4~.5~5@ P<</lang>
;bL@~.~4~.5~5@ P<</syntaxhighlight>




Example without double mod 5 check, using a flag instead, to check if Fizz already got printed (in this case the number n must not be printed if mod 5 is > 0):
Example without double mod 5 check, using a flag instead, to check if Fizz already got printed (in this case the number n must not be printed if mod 5 is > 0):


<lang beeswax> >@?q
<syntaxhighlight lang="beeswax"> >@?q
> q >Ag'd@{?p
> q >Ag'd@{?p
_>"1F3~%'d`Fizz`f>@F5~%'d`Buzz`@p
_>"1F3~%'d`Fizz`f>@F5~%'d`Buzz`@p
b P~;"-~@~.+0~P9@N?<</lang>
b P~;"-~@~.+0~P9@N?<</syntaxhighlight>


=={{header|Befunge}}==
=={{header|Befunge}}==
Line 1,229: Line 1,229:


=={{header|blz}}==
=={{header|blz}}==
<lang blz>for i = 0; i <= 100; i++
<syntaxhighlight lang="blz">for i = 0; i <= 100; i++
out = ""
out = ""
if i % 3 == 0
if i % 3 == 0
Line 1,241: Line 1,241:
end
end
print(out)
print(out)
end</lang>
end</syntaxhighlight>


=={{header|Boo}}==
=={{header|Boo}}==
<lang boo>def fizzbuzz(size):
<syntaxhighlight lang="boo">def fizzbuzz(size):
for i in range(1, size):
for i in range(1, size):
if i%15 == 0:
if i%15 == 0:
Line 1,255: Line 1,255:
print i
print i


fizzbuzz(101)</lang>
fizzbuzz(101)</syntaxhighlight>


=={{header|BQN}}==
=={{header|BQN}}==
<lang BQN>(∾´∾⟜"Fizz"‿"Buzz"/˜·(¬∨´)⊸∾0=3‿5|⊢)¨1+↕100</lang>
<syntaxhighlight lang="bqn">(∾´∾⟜"Fizz"‿"Buzz"/˜·(¬∨´)⊸∾0=3‿5|⊢)¨1+↕100</syntaxhighlight>


=={{header|Bracmat}}==
=={{header|Bracmat}}==
<lang bracmat>0:?i&whl'(1+!i:<101:?i&out$(mod$(!i.3):0&(mod$(!i.5):0&FizzBuzz|Fizz)|mod$(!i.5):0&Buzz|!i))</lang>
<syntaxhighlight lang="bracmat">0:?i&whl'(1+!i:<101:?i&out$(mod$(!i.3):0&(mod$(!i.5):0&FizzBuzz|Fizz)|mod$(!i.5):0&Buzz|!i))</syntaxhighlight>
Same code, pretty printed:
Same code, pretty printed:
<lang bracmat> 0:?i
<syntaxhighlight lang="bracmat"> 0:?i
& whl
& whl
' ( 1+!i:<101:?i
' ( 1+!i:<101:?i
Line 1,274: Line 1,274:
| !i
| !i
)
)
)</lang>
)</syntaxhighlight>


=={{header|Brainf***}}==
=={{header|Brainf***}}==
Line 1,280: Line 1,280:


=={{header|Brat}}==
=={{header|Brat}}==
<lang brat>1.to 100 { n |
<syntaxhighlight lang="brat">1.to 100 { n |
true? n % 15 == 0
true? n % 15 == 0
{ p "FizzBuzz" }
{ p "FizzBuzz" }
Line 1,290: Line 1,290:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|BrightScript (for Roku)}}==
=={{header|BrightScript (for Roku)}}==
<lang BrightScript>FOR i = 1 TO 100
<syntaxhighlight lang="brightscript">FOR i = 1 TO 100
fz = i MOD 3 = 0
fz = i MOD 3 = 0
bz = i MOD 5 = 0
bz = i MOD 5 = 0
Line 1,305: Line 1,305:
END IF
END IF
? str
? str
END FOR</lang>
END FOR</syntaxhighlight>


=={{header|C}}==
=={{header|C}}==


For 2 prime numbers and based on a similar minimal [[#JavaScript|JavaScript]] solution with low signal-to-noise, the C code is:
For 2 prime numbers and based on a similar minimal [[#JavaScript|JavaScript]] solution with low signal-to-noise, the C code is:
<lang c> int i = 0 ; char B[88] ;
<syntaxhighlight lang="c"> int i = 0 ; char B[88] ;
while ( i++ < 100 )
while ( i++ < 100 )
!sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" )
!sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" )
? sprintf( B, "%d", i ):0, printf( ", %s", B );</lang>
? sprintf( B, "%d", i ):0, printf( ", %s", B );</syntaxhighlight>
With 4 prime numbers:
With 4 prime numbers:
<lang c> int i = 0 ; char B[88] ;
<syntaxhighlight lang="c"> int i = 0 ; char B[88] ;
while ( i++ < 100 )
while ( i++ < 100 )
!sprintf( B, "%s%s%s%s",
!sprintf( B, "%s%s%s%s",
i%3 ? "":"Fiz", i%5 ? "":"Buz", i%7 ? "":"Goz", i%11 ? "":"Kaz" )
i%3 ? "":"Fiz", i%5 ? "":"Buz", i%7 ? "":"Goz", i%11 ? "":"Kaz" )
? sprintf( B, "%d", i ):0, printf( ", %s", B );</lang>
? sprintf( B, "%d", i ):0, printf( ", %s", B );</syntaxhighlight>
<lang c>Output: ..., 89, FizBuz, Goz, 92, Fiz, 94, Buz, Fiz, 97, Goz, FizKaz, Buz</lang>
<syntaxhighlight lang="c">Output: ..., 89, FizBuz, Goz, 92, Fiz, 94, Buz, Fiz, 97, Goz, FizKaz, Buz</syntaxhighlight>
One line version, with pretty printing
One line version, with pretty printing
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>


int main() {
int main() {
for (int i=1; i<=105; i++) if (i%3 && i%5) printf("%3d ", i); else printf("%s%s%s", i%3?"":"Fizz", i%5?"":"Buzz", i%15?" ":"\n");
for (int i=1; i<=105; i++) if (i%3 && i%5) printf("%3d ", i); else printf("%s%s%s", i%3?"":"Fizz", i%5?"":"Buzz", i%15?" ":"\n");
}
}
</syntaxhighlight>
</lang>


This actually works (the array init part, saves 6 bytes of static data, whee):<lang c>#include<stdio.h>
This actually works (the array init part, saves 6 bytes of static data, whee):<syntaxhighlight lang="c">#include<stdio.h>
int main ()
int main ()
Line 1,338: Line 1,338:
printf(s[!(i % 3) + 2 * !(i % 5)], i);
printf(s[!(i % 3) + 2 * !(i % 5)], i);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


<lang c>#include<stdio.h>
<syntaxhighlight lang="c">#include<stdio.h>


int main (void)
int main (void)
Line 1,359: Line 1,359:
}
}
return 0;
return 0;
}</lang>
}</syntaxhighlight>
Implicit int main and return 0 (C99+):
Implicit int main and return 0 (C99+):
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
main() {
main() {
Line 1,376: Line 1,376:
i++;
i++;
}
}
}</lang>
}</syntaxhighlight>
obfuscated:
obfuscated:
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#define F(x,y) printf("%s",i%x?"":#y"zz")
#define F(x,y) printf("%s",i%x?"":#y"zz")
int main(int i){for(--i;i++^100;puts(""))F(3,Fi)|F(5,Bu)||printf("%i",i);return 0;}</lang>
int main(int i){for(--i;i++^100;puts(""))F(3,Fi)|F(5,Bu)||printf("%i",i);return 0;}</syntaxhighlight>


With numbers theory: <lang c>#include <stdio.h>
With numbers theory: <syntaxhighlight lang="c">#include <stdio.h>


int main(void)
int main(void)
Line 1,393: Line 1,393:
}
}
}
}
</syntaxhighlight>
</lang>


Without conditionals, anything in the loop body gcc compiles with branching, duplicate tests or duplicate strings. Depends on ASCII and two's complement arithmetic:
Without conditionals, anything in the loop body gcc compiles with branching, duplicate tests or duplicate strings. Depends on ASCII and two's complement arithmetic:


<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
int main()
int main()
{
{
Line 1,407: Line 1,407:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==


<lang csharp>class Program
<syntaxhighlight lang="csharp">class Program
{
{
public void FizzBuzzGo()
public void FizzBuzzGo()
Line 1,443: Line 1,443:
}
}
}
}
}</lang>
}</syntaxhighlight>


<lang csharp>class Program
<syntaxhighlight lang="csharp">class Program
{
{
static void Main()
static void Main()
Line 1,462: Line 1,462:
}
}
}
}
}</lang>
}</syntaxhighlight>


<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Linq;
using System.Linq;


Line 1,480: Line 1,480:
}
}
}
}
}</lang>
}</syntaxhighlight>


<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Globalization;
using System.Globalization;
using System.Linq;
using System.Linq;
Line 1,504: Line 1,504:
}
}
}
}
}</lang>
}</syntaxhighlight>


<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
namespace FizzBuzz
namespace FizzBuzz
{
{
Line 1,534: Line 1,534:
}
}
}
}
}</lang>
}</syntaxhighlight>


<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Globalization;
using System.Globalization;


Line 1,565: Line 1,565:
}
}
}
}
}</lang>
}</syntaxhighlight>


<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Linq;
using System.Linq;
Line 1,579: Line 1,579:
}
}
}
}
}</lang>
}</syntaxhighlight>


===With C#8 switch expressions===
===With C#8 switch expressions===


<lang csharp>class Program
<syntaxhighlight lang="csharp">class Program
{
{
public static string FizzBuzzIt(int n) =>
public static string FizzBuzzIt(int n) =>
Line 1,601: Line 1,601:
}
}
}
}
}</lang>
}</syntaxhighlight>


===TDD using delegates===
===TDD using delegates===


<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
Line 1,687: Line 1,687:
}
}
}
}
}</lang>
}</syntaxhighlight>


===Good old C ways===
===Good old C ways===


<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
int max = 100;
int max = 100;
for(int i=0;
for(int i=0;
Line 1,697: Line 1,697:
Console.WriteLine("{0}{1}{2}", i%3==0 ? "Fizz" : "", i%5==0 ? "Buzz" : "", i%3!=0 && i%5!=0 ? i.ToString() : "")
Console.WriteLine("{0}{1}{2}", i%3==0 ? "Fizz" : "", i%5==0 ? "Buzz" : "", i%3!=0 && i%5!=0 ? i.ToString() : "")
){}
){}
</syntaxhighlight>
</lang>


=={{header|C++}}==
=={{header|C++}}==
===minimal conditions===
===minimal conditions===
<syntaxhighlight lang=cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <chrono>
#include <chrono>


Line 1,742: Line 1,742:
</syntaxhighlight>
</syntaxhighlight>
===with modulo===
===with modulo===
<syntaxhighlight lang=cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>


using namespace std;
using namespace std;
Line 1,761: Line 1,761:
}</syntaxhighlight>
}</syntaxhighlight>
===without modulo 15===
===without modulo 15===
<syntaxhighlight lang=cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
using namespace std;
using namespace std;


Line 1,782: Line 1,782:
===without modulo===
===without modulo===
Modulo can be expensive on some architectures.
Modulo can be expensive on some architectures.
<syntaxhighlight lang=cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>


int main()
int main()
Line 1,801: Line 1,801:
===using std::transform===
===using std::transform===
{{works with|C++11}}
{{works with|C++11}}
<syntaxhighlight lang=cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <algorithm>
#include <algorithm>
#include <vector>
#include <vector>
Line 1,828: Line 1,828:
===metaprogramming===
===metaprogramming===
Version computing FizzBuzz at compile time with metaprogramming:
Version computing FizzBuzz at compile time with metaprogramming:
<syntaxhighlight lang=cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>


template <int n, int m3, int m5>
template <int n, int m3, int m5>
Line 1,878: Line 1,878:
===hardcore templates===
===hardcore templates===
Compile with -ftemplate-depth-9000 -std=c++0x:
Compile with -ftemplate-depth-9000 -std=c++0x:
<syntaxhighlight lang=cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <string>
#include <string>
#include <cstdlib>
#include <cstdlib>
Line 2,048: Line 2,048:


=={{header|Cduce}}==
=={{header|Cduce}}==
<lang ocaml>(* FizzBuzz in CDuce *)
<syntaxhighlight lang="ocaml">(* FizzBuzz in CDuce *)


let format (n : Int) : Latin1 =
let format (n : Int) : Latin1 =
Line 2,065: Line 2,065:
let fizbuzz (size : Int) : _ = fizz (1, size);;
let fizbuzz (size : Int) : _ = fizz (1, size);;


let _ = fizbuzz(100);;</lang>
let _ = fizbuzz(100);;</syntaxhighlight>


=={{header|Ceylon}}==
=={{header|Ceylon}}==
<lang Ceylon>shared void run() => {for (i in 1..100) {for (j->k in [3->"Fizz", 5->"Buzz"]) if (j.divides(i)) k}.reduce(plus) else i}.each(print);</lang>
<syntaxhighlight lang="ceylon">shared void run() => {for (i in 1..100) {for (j->k in [3->"Fizz", 5->"Buzz"]) if (j.divides(i)) k}.reduce(plus) else i}.each(print);</syntaxhighlight>


=={{header|Chapel}}==
=={{header|Chapel}}==
<lang chapel>proc fizzbuzz(n) {
<syntaxhighlight lang="chapel">proc fizzbuzz(n) {
for i in 1..n do
for i in 1..n do
if i % 15 == 0 then
if i % 15 == 0 then
Line 2,083: Line 2,083:
}
}


fizzbuzz(100);</lang>
fizzbuzz(100);</syntaxhighlight>


=={{header|Chef}}==
=={{header|Chef}}==
Line 2,089: Line 2,089:


=={{header|Clay}}==
=={{header|Clay}}==
<lang clay>main() {
<syntaxhighlight lang="clay">main() {
for(i in range(1,100)) {
for(i in range(1,100)) {
if(i % 3 == 0 and i % 5 == 0) println("fizzbuzz");
if(i % 3 == 0 and i % 5 == 0) println("fizzbuzz");
Line 2,096: Line 2,096:
else print(i);
else print(i);
}
}
}</lang>
}</syntaxhighlight>


=={{header|Clipper}}==
=={{header|Clipper}}==
Also compiles with Harbour (Harbour 3.2.0dev (r1405201749))
Also compiles with Harbour (Harbour 3.2.0dev (r1405201749))
<lang Clipper>PROCEDURE Main()
<syntaxhighlight lang="clipper">PROCEDURE Main()


LOCAL n
LOCAL n
Line 2,112: Line 2,112:


RETURN
RETURN
</syntaxhighlight>
</lang>
The advantage of this approach is that it is trivial to add another factor:
The advantage of this approach is that it is trivial to add another factor:
<pre>AEval( {{3,"Fizz"},{5,"Buzz"},{9,"Jazz"}}, {|x| cFB += Iif((n % x[1])==0, x[2], "")})</pre>
<pre>AEval( {{3,"Fizz"},{5,"Buzz"},{9,"Jazz"}}, {|x| cFB += Iif((n % x[1])==0, x[2], "")})</pre>


=={{header|CLIPS}}==
=={{header|CLIPS}}==
<lang clips>(deffacts count
<syntaxhighlight lang="clips">(deffacts count
(count-to 100)
(count-to 100)
)
)
Line 2,142: Line 2,142:
(priint depth, unsigned int i> struct NUM_DIGITS_CORE : NUM_DIGITS_COREntout t crlf)
(priint depth, unsigned int i> struct NUM_DIGITS_CORE : NUM_DIGITS_COREntout t crlf)
)
)
)</lang>
)</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>
<syntaxhighlight lang="clojure">
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))
</syntaxhighlight>
</lang>


<lang clojure>
<syntaxhighlight lang="clojure">
(defn fizzbuzz [start finish]
(defn fizzbuzz [start finish]
(map (fn [n]
(map (fn [n]
Line 2,159: Line 2,159:
(range start finish)))
(range start finish)))
(fizzbuzz 1 100)
(fizzbuzz 1 100)
</syntaxhighlight>
</lang>


<lang lisp>(map (fn [x] (cond (zero? (mod x 15)) "FizzBuzz"
<syntaxhighlight lang="lisp">(map (fn [x] (cond (zero? (mod x 15)) "FizzBuzz"
(zero? (mod x 5)) "Buzz"
(zero? (mod x 5)) "Buzz"
(zero? (mod x 3)) "Fizz"
(zero? (mod x 3)) "Fizz"
:else x))
:else x))
(range 1 101))</lang>
(range 1 101))</syntaxhighlight>
<lang lisp>(map #(let [s (str (if (zero? (mod % 3)) "Fizz") (if (zero? (mod % 5)) "Buzz"))] (if (empty? s) % s)) (range 1 101))</lang>
<syntaxhighlight lang="lisp">(map #(let [s (str (if (zero? (mod % 3)) "Fizz") (if (zero? (mod % 5)) "Buzz"))] (if (empty? s) % s)) (range 1 101))</syntaxhighlight>
<lang lisp>(def fizzbuzz (map
<syntaxhighlight lang="lisp">(def fizzbuzz (map
#(cond (zero? (mod % 15)) "FizzBuzz"
#(cond (zero? (mod % 15)) "FizzBuzz"
(zero? (mod % 5)) "Buzz"
(zero? (mod % 5)) "Buzz"
(zero? (mod % 3)) "Fizz"
(zero? (mod % 3)) "Fizz"
:else %)
:else %)
(iterate inc 1)))</lang>
(iterate inc 1)))</syntaxhighlight>


<lang lisp>(defn fizz-buzz
<syntaxhighlight lang="lisp">(defn fizz-buzz
([] (fizz-buzz (range 1 101)))
([] (fizz-buzz (range 1 101)))
([lst]
([lst]
Line 2,186: Line 2,186:
(buzz? n) b
(buzz? n) b
:else n))
:else n))
lst)] items))))</lang>
lst)] items))))</syntaxhighlight>
<lang clojure>(map (fn [n]
<syntaxhighlight lang="clojure">(map (fn [n]
(if-let [fb (seq (concat (when (zero? (mod n 3)) "Fizz")
(if-let [fb (seq (concat (when (zero? (mod n 3)) "Fizz")
(when (zero? (mod n 5)) "Buzz")))]
(when (zero? (mod n 5)) "Buzz")))]
(apply str fb)
(apply str fb)
n))
n))
(range 1 101))</lang>
(range 1 101))</syntaxhighlight>
<lang clojure>(take 100 (map #(let [s (str %2 %3) ] (if (seq s) s (inc %)) )
<syntaxhighlight lang="clojure">(take 100 (map #(let [s (str %2 %3) ] (if (seq s) s (inc %)) )
(range)
(range)
(cycle [ "" "" "Fizz" ])
(cycle [ "" "" "Fizz" ])
(cycle [ "" "" "" "" "Buzz" ])))</lang>
(cycle [ "" "" "" "" "Buzz" ])))</syntaxhighlight>
<lang lisp>(map #(nth (conj (cycle [% % "Fizz" % "Buzz" "Fizz" % % "Fizz" "Buzz" % "Fizz" % % "FizzBuzz"]) %) %) (range 1 101))</lang>
<syntaxhighlight lang="lisp">(map #(nth (conj (cycle [% % "Fizz" % "Buzz" "Fizz" % % "Fizz" "Buzz" % "Fizz" % % "FizzBuzz"]) %) %) (range 1 101))</syntaxhighlight>
<lang clojure>(let [n nil fizz (cycle [n n "fizz"]) buzz (cycle [n n n n "buzz"]) nums (iterate inc 1)]
<syntaxhighlight lang="clojure">(let [n nil fizz (cycle [n n "fizz"]) buzz (cycle [n n n n "buzz"]) nums (iterate inc 1)]
(take 20 (map #(if (or %1 %2) (str %1 %2) %3) fizz buzz nums)))</lang>
(take 20 (map #(if (or %1 %2) (str %1 %2) %3) fizz buzz nums)))</syntaxhighlight>
<lang clojure>(take 100
<syntaxhighlight lang="clojure">(take 100
(map #(if (pos? (compare %1 %2)) %1 %2)
(map #(if (pos? (compare %1 %2)) %1 %2)
(map str (drop 1 (range)))
(map str (drop 1 (range)))
(map str (cycle ["" "" "Fizz"]) (cycle ["" "" "" "" "Buzz"]))))
(map str (cycle ["" "" "Fizz"]) (cycle ["" "" "" "" "Buzz"]))))
</syntaxhighlight>
</lang>
<lang clojure>
<syntaxhighlight lang="clojure">
;;Using clojure maps
;;Using clojure maps
(defn fizzbuzz
(defn fizzbuzz
Line 2,225: Line 2,225:
[max]
[max]
(map fizzbuzz (range 1 (inc max))))
(map fizzbuzz (range 1 (inc max))))
</syntaxhighlight>
</lang>
<lang clojure>
<syntaxhighlight lang="clojure">
(take 100
(take 100
(map #(str %1 %2 (if-not (or %1 %2) %3))
(map #(str %1 %2 (if-not (or %1 %2) %3))
Line 2,233: Line 2,233:
(rest (range))
(rest (range))
))
))
</syntaxhighlight>
</lang>


<lang clojure>
<syntaxhighlight lang="clojure">
(take 100
(take 100
(
(
Line 2,254: Line 2,254:
) ;;endfn apply
) ;;endfn apply
) ;;endtake
) ;;endtake
</syntaxhighlight>
</lang>


<lang clojure>
<syntaxhighlight lang="clojure">
(take 100
(take 100
(map-indexed
(map-indexed
Line 2,263: Line 2,263:
)
)
)
)
</syntaxhighlight>
</lang>


<lang clojure>
<syntaxhighlight lang="clojure">
(take 100
(take 100
(->>
(->>
Line 2,272: Line 2,272:
)
)
)
)
</syntaxhighlight>
</lang>


<lang clojure>
<syntaxhighlight lang="clojure">
(take 100
(take 100
(map-indexed
(map-indexed
Line 2,281: Line 2,281:
)
)
)
)
</syntaxhighlight>
</lang>


=={{header|CLU}}==
=={{header|CLU}}==
<lang clu>start_up = proc ()
<syntaxhighlight lang="clu">start_up = proc ()
po: stream := stream$primary_output()
po: stream := stream$primary_output()
Line 2,294: Line 2,294:
stream$putl(po, out)
stream$putl(po, out)
end
end
end start_up</lang>
end start_up</syntaxhighlight>


=={{header|CMake}}==
=={{header|CMake}}==
<lang cmake>foreach(i RANGE 1 100)
<syntaxhighlight lang="cmake">foreach(i RANGE 1 100)
math(EXPR off3 "${i} % 3")
math(EXPR off3 "${i} % 3")
math(EXPR off5 "${i} % 5")
math(EXPR off5 "${i} % 5")
Line 2,309: Line 2,309:
message(${i})
message(${i})
endif()
endif()
endforeach(i)</lang>
endforeach(i)</syntaxhighlight>


=={{header|COBOL}}==
=={{header|COBOL}}==
Line 2,315: Line 2,315:
===Canonical version===
===Canonical version===
{{works with|OpenCOBOL}}<!-- http://www.opencobol.org/ -->
{{works with|OpenCOBOL}}<!-- http://www.opencobol.org/ -->
<lang COBOL> * FIZZBUZZ.COB
<syntaxhighlight lang="cobol"> * FIZZBUZZ.COB
* cobc -x -g FIZZBUZZ.COB
* cobc -x -g FIZZBUZZ.COB
*
*
Line 2,350: Line 2,350:
END-PERFORM
END-PERFORM
DISPLAY ""
DISPLAY ""
STOP RUN.</lang>
STOP RUN.</syntaxhighlight>
===Simpler version===
===Simpler version===
I know this doesn't have the full-bodied, piquant flavor
I know this doesn't have the full-bodied, piquant flavor
expected from COBOL, but it is a little shorter.
expected from COBOL, but it is a little shorter.
{{works with|OpenCOBOL}}
{{works with|OpenCOBOL}}
<lang cobol>Identification division.
<syntaxhighlight lang="cobol">Identification division.
Program-id. fizz-buzz.
Program-id. fizz-buzz.


Line 2,370: Line 2,370:
else display num
else display num
end-perform.
end-perform.
Stop run.</lang>
Stop run.</syntaxhighlight>
===Evaluate Version===
===Evaluate Version===
I think this shows clearly that it's resolving the problem and illuminating the rules specified
I think this shows clearly that it's resolving the problem and illuminating the rules specified
{{works with|OpenCOBOL}}
{{works with|OpenCOBOL}}
<lang cobol>
<syntaxhighlight lang="cobol">
IDENTIFICATION DIVISION.
IDENTIFICATION DIVISION.
PROGRAM-ID. FIZZBUZZ.
PROGRAM-ID. FIZZBUZZ.
Line 2,401: Line 2,401:
STOP RUN
STOP RUN
.
.
</syntaxhighlight>
</lang>


===Chase the Fizz===
===Chase the Fizz===
{{works with|OpenCOBOL}}
{{works with|OpenCOBOL}}
A solution that simply evaluates and adds.
A solution that simply evaluates and adds.
<lang cobol> >>SOURCE FORMAT FREE
<syntaxhighlight lang="cobol"> >>SOURCE FORMAT FREE
identification division.
identification division.
program-id. fizzbuzz.
program-id. fizzbuzz.
Line 2,435: Line 2,435:
.
.
end program fizzbuzz.
end program fizzbuzz.
</syntaxhighlight>
</lang>


=={{header|Coco}}==
=={{header|Coco}}==
<lang coco>for i from 1 to 100
<syntaxhighlight lang="coco">for i from 1 to 100
console.log do
console.log do
if i % 15 == 0 then 'FizzBuzz'
if i % 15 == 0 then 'FizzBuzz'
else if i % 3 == 0 then 'Fizz'
else if i % 3 == 0 then 'Fizz'
else if i % 5 == 0 then 'Buzz'
else if i % 5 == 0 then 'Buzz'
else i</lang>
else i</syntaxhighlight>


<lang coco>for i from 1 to 100
<syntaxhighlight lang="coco">for i from 1 to 100
console.log(['Fizz' unless i % 3] + ['Buzz' unless i % 5] or String(i))</lang>
console.log(['Fizz' unless i % 3] + ['Buzz' unless i % 5] or String(i))</syntaxhighlight>


=={{header|Coconut}}==
=={{header|Coconut}}==
<lang Coconut>def fizzbuzz(n):
<syntaxhighlight lang="coconut">def fizzbuzz(n):
case (n % 3, n % 5):
case (n % 3, n % 5):
match (0, 0): return "FizzBuzz"
match (0, 0): return "FizzBuzz"
Line 2,455: Line 2,455:
match (_, 0): return "Buzz"
match (_, 0): return "Buzz"
else: return n |> str
else: return n |> str
range(1,101)|> map$(fizzbuzz)|> x -> '\n'.join(x)|> print</lang>
range(1,101)|> map$(fizzbuzz)|> x -> '\n'.join(x)|> print</syntaxhighlight>


=={{header|CoffeeScript}}==
=={{header|CoffeeScript}}==
<lang CoffeeScript>for i in [1..100]
<syntaxhighlight lang="coffeescript">for i in [1..100]
if i % 15 is 0
if i % 15 is 0
console.log "FizzBuzz"
console.log "FizzBuzz"
Line 2,466: Line 2,466:
console.log "Buzz"
console.log "Buzz"
else
else
console.log i</lang>
console.log i</syntaxhighlight>
<lang CoffeeScript>for i in [1..100]
<syntaxhighlight lang="coffeescript">for i in [1..100]
console.log \
console.log \
if i % 15 is 0
if i % 15 is 0
Line 2,476: Line 2,476:
"Buzz"
"Buzz"
else
else
i</lang>
i</syntaxhighlight>
<lang CoffeeScript>for i in [1..100]
<syntaxhighlight lang="coffeescript">for i in [1..100]
console.log(['Fizz' if i % 3 is 0] + ['Buzz' if i % 5 is 0] or i)</lang>
console.log(['Fizz' if i % 3 is 0] + ['Buzz' if i % 5 is 0] or i)</syntaxhighlight>


=={{header|ColdFusion}}==
=={{header|ColdFusion}}==
<lang cfm><Cfloop from="1" to="100" index="i">
<syntaxhighlight lang="cfm"><Cfloop from="1" to="100" index="i">
<Cfif i mod 15 eq 0>FizzBuzz
<Cfif i mod 15 eq 0>FizzBuzz
<Cfelseif i mod 5 eq 0>Fizz
<Cfelseif i mod 5 eq 0>Fizz
Line 2,487: Line 2,487:
<Cfelse><Cfoutput>#i# </Cfoutput>
<Cfelse><Cfoutput>#i# </Cfoutput>
</Cfif>
</Cfif>
</Cfloop></lang>
</Cfloop></syntaxhighlight>
cfscript version
cfscript version
<lang cfm><cfscript>
<syntaxhighlight lang="cfm"><cfscript>
result = "";
result = "";
for(i=1;i<=100;i++){
for(i=1;i<=100;i++){
Line 2,495: Line 2,495:
}
}
WriteOutput(result);
WriteOutput(result);
</cfscript></lang>
</cfscript></syntaxhighlight>


=={{header|Comal}}==
=={{header|Comal}}==
<lang comal>0010 FOR i#:=1 TO 100 DO
<syntaxhighlight lang="comal">0010 FOR i#:=1 TO 100 DO
0020 IF i# MOD 15=0 THEN
0020 IF i# MOD 15=0 THEN
0030 PRINT "FizzBuzz"
0030 PRINT "FizzBuzz"
Line 2,509: Line 2,509:
0100 ENDIF
0100 ENDIF
0110 ENDFOR i#
0110 ENDFOR i#
0120 END</lang>
0120 END</syntaxhighlight>


=={{header|Comefrom0x10}}==
=={{header|Comefrom0x10}}==


<lang cf0x10>fizzbuzz
<syntaxhighlight lang="cf0x10">fizzbuzz
mod_three = 3
mod_three = 3
mod_five = 5
mod_five = 5
Line 2,536: Line 2,536:
mod_five = mod_five + 5
mod_five = mod_five + 5


comefrom fizzbuzz if n is 100</lang>
comefrom fizzbuzz if n is 100</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Solution 1:
Solution 1:
<lang lisp>(defun fizzbuzz ()
<syntaxhighlight lang="lisp">(defun fizzbuzz ()
(loop for x from 1 to 100 do
(loop for x from 1 to 100 do
(princ (cond ((zerop (mod x 15)) "FizzBuzz")
(princ (cond ((zerop (mod x 15)) "FizzBuzz")
Line 2,546: Line 2,546:
((zerop (mod x 5)) "Buzz")
((zerop (mod x 5)) "Buzz")
(t x)))
(t x)))
(terpri)))</lang>
(terpri)))</syntaxhighlight>
Solution 2:
Solution 2:
<lang lisp>(defun fizzbuzz ()
<syntaxhighlight lang="lisp">(defun fizzbuzz ()
(loop for x from 1 to 100 do
(loop for x from 1 to 100 do
(format t "~&~{~A~}"
(format t "~&~{~A~}"
(or (append (when (zerop (mod x 3)) '("Fizz"))
(or (append (when (zerop (mod x 3)) '("Fizz"))
(when (zerop (mod x 5)) '("Buzz")))
(when (zerop (mod x 5)) '("Buzz")))
(list x)))))</lang>
(list x)))))</syntaxhighlight>
Solution 3:
Solution 3:
<lang lisp>(defun fizzbuzz ()
<syntaxhighlight lang="lisp">(defun fizzbuzz ()
(loop for n from 1 to 100
(loop for n from 1 to 100
do (format t "~&~[~[FizzBuzz~:;Fizz~]~*~:;~[Buzz~*~:;~D~]~]~%"
do (format t "~&~[~[FizzBuzz~:;Fizz~]~*~:;~[Buzz~*~:;~D~]~]~%"
(mod n 3) (mod n 5) n)))</lang>
(mod n 3) (mod n 5) n)))</syntaxhighlight>
Solution 4:
Solution 4:
<lang lisp>(loop as n from 1 to 100
<syntaxhighlight lang="lisp">(loop as n from 1 to 100
as fizz = (zerop (mod n 3))
as fizz = (zerop (mod n 3))
as buzz = (zerop (mod n 5))
as buzz = (zerop (mod n 5))
Line 2,567: Line 2,567:
(format t
(format t
"~&~:[~;Fizz~]~:[~;Buzz~]~:[~;~D~]~%"
"~&~:[~;Fizz~]~:[~;Buzz~]~:[~;~D~]~%"
fizz buzz numb n))</lang>
fizz buzz numb n))</syntaxhighlight>
Solution 5:
Solution 5:
<lang lisp>(format t "~{~:[~&~;~:*~:(~a~)~]~}"
<syntaxhighlight lang="lisp">(format t "~{~:[~&~;~:*~:(~a~)~]~}"
(loop as n from 1 to 100
(loop as n from 1 to 100
as f = (zerop (mod n 3))
as f = (zerop (mod n 3))
Line 2,576: Line 2,576:
if f collect 'fizz
if f collect 'fizz
if b collect 'buzz
if b collect 'buzz
if (not (or f b)) collect n))</lang>
if (not (or f b)) collect n))</syntaxhighlight>
Solution 6:
Solution 6:
<lang lisp>(format t "~{~{~:[~;Fizz~]~:[~;Buzz~]~:[~*~;~d~]~}~%~}"
<syntaxhighlight lang="lisp">(format t "~{~{~:[~;Fizz~]~:[~;Buzz~]~:[~*~;~d~]~}~%~}"
(loop as n from 1 to 100
(loop as n from 1 to 100
as f = (zerop (mod n 3))
as f = (zerop (mod n 3))
as b = (zerop (mod n 5))
as b = (zerop (mod n 5))
collect (list f b (not (or f b)) n)))</lang>
collect (list f b (not (or f b)) n)))</syntaxhighlight>


Solution 7:
Solution 7:
<lang lisp>(defun core (x)
<syntaxhighlight lang="lisp">(defun core (x)
(mapcar
(mapcar
#'(lambda (a b) (if (equal 0 (mod x a)) b x))
#'(lambda (a b) (if (equal 0 (mod x a)) b x))
Line 2,600: Line 2,600:
(print (format nil "~{~a~}" (filter-core (core a))))))
(print (format nil "~{~a~}" (filter-core (core a))))))


(fizzbuzz 100)</lang>
(fizzbuzz 100)</syntaxhighlight>
First 16 lines of output:
First 16 lines of output:
<pre>
<pre>
Line 2,624: Line 2,624:
I use [https://franz.com/downloads/clp/survey Allegro CL 10.1]
I use [https://franz.com/downloads/clp/survey Allegro CL 10.1]


<lang lisp>
<syntaxhighlight lang="lisp">
;; Project : FizzBuzz
;; Project : FizzBuzz


Line 2,645: Line 2,645:
(= (rem n multiple) 0))
(= (rem n multiple) 0))
(fizzbuzz 1)
(fizzbuzz 1)
</syntaxhighlight>
</lang>
Output:
Output:
<pre>
<pre>
Line 2,673: Line 2,673:
=={{header|Coq}}==
=={{header|Coq}}==


<lang coq>
<syntaxhighlight lang="coq">
Require Import Coq.Lists.List.
Require Import Coq.Lists.List.
(* https://coq.inria.fr/library/Coq.Lists.List.html *)
(* https://coq.inria.fr/library/Coq.Lists.List.html *)
Line 2,740: Line 2,740:
(** This shows the string. *)
(** This shows the string. *)
Eval compute in fizz_buzz.
Eval compute in fizz_buzz.
</syntaxhighlight>
</lang>




Line 2,747: Line 2,747:
===Straightforward version===
===Straightforward version===


<lang cowgol>include "cowgol.coh";
<syntaxhighlight lang="cowgol">include "cowgol.coh";


var i: uint8 := 1;
var i: uint8 := 1;
Line 2,762: Line 2,762:
print_nl();
print_nl();
i := i + 1;
i := i + 1;
end loop;</lang>
end loop;</syntaxhighlight>


===No division===
===No division===
Line 2,781: Line 2,781:
98-byte executable.)
98-byte executable.)


<lang cowgol>include "cowgol.coh";
<syntaxhighlight lang="cowgol">include "cowgol.coh";


var i: uint8 := 100;
var i: uint8 := 100;
Line 2,823: Line 2,823:
i := i - 1;
i := i - 1;
end loop;
end loop;
</syntaxhighlight>
</lang>


=={{header|Crystal}}==
=={{header|Crystal}}==
<lang ruby>1.upto(100) do |v|
<syntaxhighlight lang="ruby">1.upto(100) do |v|
p fizz_buzz(v)
p fizz_buzz(v)
end
end
Line 2,837: Line 2,837:
word += value.to_s if word.empty?
word += value.to_s if word.empty?
word
word
end</lang>
end</syntaxhighlight>


A more natural solution with the string building:
A more natural solution with the string building:


<lang ruby>1.upto(100) do |n|
<syntaxhighlight lang="ruby">1.upto(100) do |n|
case
case
when n % 15 == 0
when n % 15 == 0
Line 2,852: Line 2,852:
puts n
puts n
end
end
end</lang>
end</syntaxhighlight>


=={{header|CSS}}==
=={{header|CSS}}==
Line 2,982: Line 2,982:


=={{header|Cubescript}}==
=={{header|Cubescript}}==
<lang>alias fizzbuzz [
<syntaxhighlight lang="text">alias fizzbuzz [
loop i 100 [
loop i 100 [
push i (+ $i 1) [
push i (+ $i 1) [
Line 2,996: Line 2,996:
]
]
]
]
]</lang>
]</syntaxhighlight>


=={{header|D}}==
=={{header|D}}==
<lang d>import std.stdio, std.algorithm, std.conv;
<syntaxhighlight lang="d">import std.stdio, std.algorithm, std.conv;


/// With if-else.
/// With if-else.
Line 3,051: Line 3,051:
writeln;
writeln;
100.fizzBuzzSwitch2;
100.fizzBuzzSwitch2;
}</lang>
}</syntaxhighlight>
Alternate version calculating values at compile time:
Alternate version calculating values at compile time:
<lang d>import std;
<syntaxhighlight lang="d">import std;


void main()
void main()
Line 3,069: Line 3,069:


r.each!writeln;
r.each!writeln;
}</lang>
}</syntaxhighlight>


=={{header|Dart}}==
=={{header|Dart}}==
<lang dart>
<syntaxhighlight lang="dart">
main() {
main() {
for (int i = 1; i <= 100; i++) {
for (int i = 1; i <= 100; i++) {
Line 3,083: Line 3,083:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|dc}}==
=={{header|dc}}==
{{trans|bc}}
{{trans|bc}}
<lang dc>[[Fizz]P 1 sw]sF
<syntaxhighlight lang="dc">[[Fizz]P 1 sw]sF
[[Buzz]P 1 sw]sB
[[Buzz]P 1 sw]sB
[li p sz]sN
[li p sz]sN
Line 3,102: Line 3,102:
]sL
]sL
1 si [i = 1]sz
1 si [i = 1]sz
0 0 =L [enter Loop]sz</lang>
0 0 =L [enter Loop]sz</syntaxhighlight>
The bc translation written in dc style.
The bc translation written in dc style.
<syntaxhighlight lang="dc">
<lang dc>
# dc is stack based, so we use the stack instead of a variable for our
# dc is stack based, so we use the stack instead of a variable for our
# current number.
# current number.
Line 3,122: Line 3,122:
1+d # Number += 1 and put extra copy on stack
1+d # Number += 1 and put extra copy on stack
100!<L # Continue Loop if 100 >= Number (destroys copy)
100!<L # Continue Loop if 100 >= Number (destroys copy)
]dsLx # Enter Loop</lang>
]dsLx # Enter Loop</syntaxhighlight>


=={{header|Delphi}}==
=={{header|Delphi}}==
<lang Delphi>program FizzBuzz;
<syntaxhighlight lang="delphi">program FizzBuzz;


{$APPTYPE CONSOLE}
{$APPTYPE CONSOLE}
Line 3,145: Line 3,145:
Writeln(i);
Writeln(i);
end;
end;
end.</lang>
end.</syntaxhighlight>


=={{header|DeviousYarn}}==
=={{header|DeviousYarn}}==
<lang deviousyarn>each { x range(1 100)
<syntaxhighlight lang="deviousyarn">each { x range(1 100)
? { divisible(x 3)
? { divisible(x 3)
p:'Fizz' }
p:'Fizz' }
Line 3,156: Line 3,156:
p:x }
p:x }
o
o
}</lang>
}</syntaxhighlight>


=={{header|Draco}}==
=={{header|Draco}}==
<lang draco>proc nonrec main() void:
<syntaxhighlight lang="draco">proc nonrec main() void:
byte i;
byte i;
for i from 1 upto 100 do
for i from 1 upto 100 do
Line 3,168: Line 3,168:
fi
fi
od
od
corp</lang>
corp</syntaxhighlight>


=={{header|DUP}}==
=={{header|DUP}}==
Line 3,175: Line 3,175:


Output to STDOUT via single character output.
Output to STDOUT via single character output.
<lang DUP>[$$3/%$[]['F,'i,'z,'z,]?\5/%$[]['B,'u,'z,'z,]?*[$.][]?10,]c: {define function c: mod 3, mod 5 tests, print proper output}
<syntaxhighlight lang="dup">[$$3/%$[]['F,'i,'z,'z,]?\5/%$[]['B,'u,'z,'z,]?*[$.][]?10,]c: {define function c: mod 3, mod 5 tests, print proper output}
0[$100<][1+c;!]# {loop from 1 to 100}</lang>
0[$100<][1+c;!]# {loop from 1 to 100}</syntaxhighlight>


Output to STDOUT, using stored strings and a separately defined string output operator:
Output to STDOUT, using stored strings and a separately defined string output operator:
<lang DUP>[\[^^>][$;,1+]#%%]⇒P {define operator P: print stored string}
<syntaxhighlight lang="dup">[\[^^>][$;,1+]#%%]⇒P {define operator P: print stored string}
[$$3/%$[][0$"Fizz"P]?\5/%$[][0$"Buzz"P]?*[$.][]?10,]c: {define function c: mod 3, mod 5 tests, print according output}
[$$3/%$[][0$"Fizz"P]?\5/%$[][0$"Buzz"P]?*[$.][]?10,]c: {define function c: mod 3, mod 5 tests, print according output}
0[$100<][1+c;!]# {loop from 1 to 100}</lang>
0[$100<][1+c;!]# {loop from 1 to 100}</syntaxhighlight>


=={{header|DWScript}}==
=={{header|DWScript}}==
<lang delphi>var i : Integer;
<syntaxhighlight lang="delphi">var i : Integer;


for i := 1 to 100 do begin
for i := 1 to 100 do begin
Line 3,194: Line 3,194:
PrintLn('Buzz')
PrintLn('Buzz')
else PrintLn(i);
else PrintLn(i);
end;</lang>
end;</syntaxhighlight>


=={{header|Dyalect}}==
=={{header|Dyalect}}==


<lang Dyalect>var n = 1
<syntaxhighlight lang="dyalect">var n = 1


while n < 20 {
while n < 20 {
Line 3,212: Line 3,212:


n = n + 1
n = n + 1
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 3,237: Line 3,237:


=={{header|Déjà Vu}}==
=={{header|Déjà Vu}}==
<lang dejavu>for i range 1 100:
<syntaxhighlight lang="dejavu">for i range 1 100:
if = 0 % i 15:
if = 0 % i 15:
"FizzBuzz"
"FizzBuzz"
Line 3,246: Line 3,246:
else:
else:
i
i
!print</lang>
!print</syntaxhighlight>


=={{header|E}}==
=={{header|E}}==
<lang e>for i in 1..100 {
<syntaxhighlight lang="e">for i in 1..100 {
println(switch ([i % 3, i % 5]) {
println(switch ([i % 3, i % 5]) {
match [==0, ==0] { "FizzBuzz" }
match [==0, ==0] { "FizzBuzz" }
Line 3,256: Line 3,256:
match _ { i }
match _ { i }
})
})
}</lang>
}</syntaxhighlight>


=={{header|EasyLang}}==
=={{header|EasyLang}}==
<lang>for i = 1 to 100
<syntaxhighlight lang="text">for i = 1 to 100
if i mod 15 = 0
if i mod 15 = 0
print "FizzBuzz"
print "FizzBuzz"
Line 3,269: Line 3,269:
print i
print i
.
.
.</lang>
.</syntaxhighlight>


=={{header|ECL}}==
=={{header|ECL}}==
<lang ECL>DataRec := RECORD
<syntaxhighlight lang="ecl">DataRec := RECORD
STRING s;
STRING s;
END;
END;
Line 3,288: Line 3,288:
d := DATASET(100,MakeDataRec(COUNTER));
d := DATASET(100,MakeDataRec(COUNTER));


OUTPUT(d);</lang>
OUTPUT(d);</syntaxhighlight>


=={{header|Eero}}==
=={{header|Eero}}==
<lang objc>#import <Foundation/Foundation.h>
<syntaxhighlight lang="objc">#import <Foundation/Foundation.h>


int main()
int main()
Line 3,304: Line 3,304:
Log( '(%d) %@', i, s )
Log( '(%d) %@', i, s )


return 0</lang>
return 0</syntaxhighlight>


=={{header|Egel}}==
=={{header|Egel}}==
<syntaxhighlight lang="egel">
<lang Egel>
import "prelude.eg"
import "prelude.eg"
import "io.ego"
import "io.ego"
Line 3,327: Line 3,327:


def main = fizzbuzz 1
def main = fizzbuzz 1
</syntaxhighlight>
</lang>


=={{header|Eiffel}}==
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">
<lang Eiffel>
class
class
APPLICATION
APPLICATION
Line 3,365: Line 3,365:
end
end


</syntaxhighlight>
</lang>


=={{header|Ela}}==
=={{header|Ela}}==
<lang ela>open list
<syntaxhighlight lang="ela">open list


prt x | x % 15 == 0 = "FizzBuzz"
prt x | x % 15 == 0 = "FizzBuzz"
Line 3,375: Line 3,375:
| else = x
| else = x


[1..100] |> map prt</lang>
[1..100] |> map prt</syntaxhighlight>


=={{header|Elixir}}==
=={{header|Elixir}}==
===Standard approaches===
===Standard approaches===
used case
used case
<lang elixir>Enum.each 1..100, fn x ->
<syntaxhighlight lang="elixir">Enum.each 1..100, fn x ->
IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do
IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do
{ true, true } -> "FizzBuzz"
{ true, true } -> "FizzBuzz"
Line 3,387: Line 3,387:
{ false, false } -> x
{ false, false } -> x
end)
end)
end</lang>
end</syntaxhighlight>


Alternate approach using pipes and cond:
Alternate approach using pipes and cond:


<lang elixir>#!/usr/bin/env elixir
<syntaxhighlight lang="elixir">#!/usr/bin/env elixir
1..100 |> Enum.map(fn i ->
1..100 |> Enum.map(fn i ->
cond do
cond do
Line 3,399: Line 3,399:
true -> i
true -> i
end
end
end) |> Enum.each(fn i -> IO.puts i end)</lang>
end) |> Enum.each(fn i -> IO.puts i end)</syntaxhighlight>


used Stream.cycle version:
used Stream.cycle version:
<lang elixir>defmodule RC do
<syntaxhighlight lang="elixir">defmodule RC do
def fizzbuzz(limit \\ 100) do
def fizzbuzz(limit \\ 100) do
fizz = Stream.cycle(["", "", "Fizz"])
fizz = Stream.cycle(["", "", "Fizz"])
Line 3,415: Line 3,415:
end
end


RC.fizzbuzz</lang>
RC.fizzbuzz</syntaxhighlight>


Yet another approach:
Yet another approach:
<lang elixir>defmodule FizzBuzz do
<syntaxhighlight lang="elixir">defmodule FizzBuzz do
def fizzbuzz(n) when rem(n, 15) == 0, do: "FizzBuzz"
def fizzbuzz(n) when rem(n, 15) == 0, do: "FizzBuzz"
def fizzbuzz(n) when rem(n, 5) == 0, do: "Buzz"
def fizzbuzz(n) when rem(n, 5) == 0, do: "Buzz"
Line 3,425: Line 3,425:
end
end


Enum.each(1..100, &IO.puts FizzBuzz.fizzbuzz &1)</lang>
Enum.each(1..100, &IO.puts FizzBuzz.fizzbuzz &1)</syntaxhighlight>


used anonymous function
used anonymous function
<lang elixir>f = fn(n) when rem(n,15)==0 -> "FizzBuzz"
<syntaxhighlight lang="elixir">f = fn(n) when rem(n,15)==0 -> "FizzBuzz"
(n) when rem(n,5)==0 -> "Fizz"
(n) when rem(n,5)==0 -> "Fizz"
(n) when rem(n,3)==0 -> "Buzz"
(n) when rem(n,3)==0 -> "Buzz"
Line 3,434: Line 3,434:
end
end


for n <- 1..100, do: IO.puts f.(n)</lang>
for n <- 1..100, do: IO.puts f.(n)</syntaxhighlight>


Enum.at version: Returns nil if index is out of bounds.
Enum.at version: Returns nil if index is out of bounds.
<lang elixir>Enum.each(1..100, fn i ->
<syntaxhighlight lang="elixir">Enum.each(1..100, fn i ->
str = "#{Enum.at([:Fizz], rem(i,3))}#{Enum.at([:Buzz], rem(i,5))}"
str = "#{Enum.at([:Fizz], rem(i,3))}#{Enum.at([:Buzz], rem(i,5))}"
IO.puts if str=="", do: i, else: str
IO.puts if str=="", do: i, else: str
end)</lang>
end)</syntaxhighlight>


===A macro too far===
===A macro too far===
The Stream.cycle version above, but as an overpowered FizzBuzz DSL.
The Stream.cycle version above, but as an overpowered FizzBuzz DSL.
<lang elixir>defmodule BadFizz do
<syntaxhighlight lang="elixir">defmodule BadFizz do
# Hand-rolls a bunch of AST before injecting the resulting FizzBuzz code.
# Hand-rolls a bunch of AST before injecting the resulting FizzBuzz code.
defmacrop automate_fizz(fizzers, n) do
defmacrop automate_fizz(fizzers, n) do
Line 3,534: Line 3,534:
end
end


BadFizz.fizz(100) # => Prints to stdout</lang>
BadFizz.fizz(100) # => Prints to stdout</syntaxhighlight>


=={{header|Elm}}==
=={{header|Elm}}==
A bit too simple:
A bit too simple:
<lang elm>import Html exposing (text)
<syntaxhighlight lang="elm">import Html exposing (text)
import List exposing (map)
import List exposing (map)


Line 3,552: Line 3,552:
"Buzz"
"Buzz"
else
else
String.fromInt num</lang>
String.fromInt num</syntaxhighlight>


A bit too clever:
A bit too clever:
<lang elm>import Html exposing (text)
<syntaxhighlight lang="elm">import Html exposing (text)
import List exposing (map)
import List exposing (map)
import String exposing (join, fromInt)
import String exposing (join, fromInt)
Line 3,572: Line 3,572:
fromInt num
fromInt num
else
else
fizz ++ buzz</lang>
fizz ++ buzz</syntaxhighlight>


=={{header|Emacs Lisp}}==
=={{header|Emacs Lisp}}==
<lang Lisp>(defun fizzbuzz (n)
<syntaxhighlight lang="lisp">(defun fizzbuzz (n)
(cond ((and (zerop (% n 5)) (zerop (% n 3))) "FizzBuzz")
(cond ((and (zerop (% n 5)) (zerop (% n 3))) "FizzBuzz")
((zerop (% n 3)) "Fizz")
((zerop (% n 3)) "Fizz")
Line 3,583: Line 3,583:
;; loop & print from 0 to 100
;; loop & print from 0 to 100
(dotimes (i 101)
(dotimes (i 101)
(message "%s" (fizzbuzz i)))</lang>
(message "%s" (fizzbuzz i)))</syntaxhighlight>


=={{header|Emojicode}}==
=={{header|Emojicode}}==
===Simple 1===
===Simple 1===
<lang Emojicode>🏁🍇
<syntaxhighlight lang="emojicode">🏁🍇
🔂 i 🆕⏩ 1 101 1 ❗ 🍇
🔂 i 🆕⏩ 1 101 1 ❗ 🍇
↪️ i 🚮 15 🙌 0 🍇
↪️ i 🚮 15 🙌 0 🍇
Line 3,601: Line 3,601:
🍉
🍉
🍉
🍉
🍉</lang>
🍉</syntaxhighlight>
===Simple 2===
===Simple 2===
<lang Emojicode>🏁🍇
<syntaxhighlight lang="emojicode">🏁🍇
🔂 i 🆕⏩ 1 101 1 ❗ 🍇
🔂 i 🆕⏩ 1 101 1 ❗ 🍇
🔤🔤 ➡️ 🖍🆕 msg
🔤🔤 ➡️ 🖍🆕 msg
Line 3,618: Line 3,618:
🍉
🍉
🍉
🍉
🍉</lang>
🍉</syntaxhighlight>


=={{header|Erlang}}==
=={{header|Erlang}}==
<lang erlang>-spec fizzbuzz() -> Result :: string().
<syntaxhighlight lang="erlang">-spec fizzbuzz() -> Result :: string().
fizzbuzz() ->
fizzbuzz() ->
F = fun(N) when N rem 15 == 0 -> "FizzBuzz";
F = fun(N) when N rem 15 == 0 -> "FizzBuzz";
Line 3,628: Line 3,628:
(N) -> integer_to_list(N)
(N) -> integer_to_list(N)
end,
end,
lists:flatten([[F(N)] ++ ["\n"] || N <- lists:seq(1,100)]).</lang>
lists:flatten([[F(N)] ++ ["\n"] || N <- lists:seq(1,100)]).</syntaxhighlight>


=={{header|ERRE}}==
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
<lang ERRE>
PROGRAM FIZZ_BUZZ
PROGRAM FIZZ_BUZZ
!
!
Line 3,649: Line 3,649:
END FOR
END FOR
END PROGRAM
END PROGRAM
</syntaxhighlight>
</lang>


=={{header|Euphoria}}==
=={{header|Euphoria}}==
{{works with|Euphoria|4.0.0}}
{{works with|Euphoria|4.0.0}}
This is based on the [[VBScript]] example.
This is based on the [[VBScript]] example.
<lang Euphoria>include std/utils.e
<syntaxhighlight lang="euphoria">include std/utils.e


function fb( atom n )
function fb( atom n )
Line 3,686: Line 3,686:
end for
end for


puts( 1, "\n" )</lang>
puts( 1, "\n" )</syntaxhighlight>


=={{header|F Sharp|F#}}==
=={{header|F Sharp|F#}}==
<lang fsharp>let fizzbuzz n =
<syntaxhighlight lang="fsharp">let fizzbuzz n =
match n%3 = 0, n%5 = 0 with
match n%3 = 0, n%5 = 0 with
| true, false -> "fizz"
| true, false -> "fizz"
Line 3,697: Line 3,697:


let printFizzbuzz() =
let printFizzbuzz() =
[1..100] |> List.iter (fizzbuzz >> printfn "%s")</lang>
[1..100] |> List.iter (fizzbuzz >> printfn "%s")</syntaxhighlight>
<lang fsharp>[1..100]
<syntaxhighlight lang="fsharp">[1..100]
|> List.map (fun x ->
|> List.map (fun x ->
match x with
match x with
Line 3,705: Line 3,705:
| _ when x % 3 = 0 -> "fizz"
| _ when x % 3 = 0 -> "fizz"
| _ -> x.ToString())
| _ -> x.ToString())
|> List.iter (fun x -> printfn "%s" x) </lang>
|> List.iter (fun x -> printfn "%s" x) </syntaxhighlight>
Another example using (unnecessary) partial active pattern :D
Another example using (unnecessary) partial active pattern :D
<lang fsharp>let (|MultipleOf|_|) divisors number =
<syntaxhighlight lang="fsharp">let (|MultipleOf|_|) divisors number =
if Seq.exists ((%) number >> (<>) 0) divisors
if Seq.exists ((%) number >> (<>) 0) divisors
then None
then None
Line 3,719: Line 3,719:


{ 1 .. 100 }
{ 1 .. 100 }
|> Seq.iter (fizzbuzz >> printfn "%s")</lang>
|> Seq.iter (fizzbuzz >> printfn "%s")</syntaxhighlight>


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: math kernel io math.functions math.parser math.ranges ;
<syntaxhighlight lang="factor">USING: math kernel io math.functions math.parser math.ranges ;
IN: fizzbuzz
IN: fizzbuzz
: fizz ( n -- str ) 3 divisor? "Fizz" "" ? ;
: fizz ( n -- str ) 3 divisor? "Fizz" "" ? ;
Line 3,728: Line 3,728:
: fizzbuzz ( n -- str ) dup [ fizz ] [ buzz ] bi append [ number>string ] [ nip ] if-empty ;
: fizzbuzz ( n -- str ) dup [ fizz ] [ buzz ] bi append [ number>string ] [ nip ] if-empty ;
: main ( -- ) 100 [1,b] [ fizzbuzz print ] each ;
: main ( -- ) 100 [1,b] [ fizzbuzz print ] each ;
MAIN: main</lang>
MAIN: main</syntaxhighlight>


More flexible variant without divisibility tests.
More flexible variant without divisibility tests.
<lang factor>
<syntaxhighlight lang="factor">
USING: kernel sequences arrays generalizations fry math math.parser prettyprint ;
USING: kernel sequences arrays generalizations fry math math.parser prettyprint ;
IN: fizzbuzz
IN: fizzbuzz
Line 3,751: Line 3,751:


MAIN: FizzBuzzQuxx-100
MAIN: FizzBuzzQuxx-100
</syntaxhighlight>
</lang>


=={{header|Falcon}}==
=={{header|Falcon}}==
<lang falcon>for i in [1:101]
<syntaxhighlight lang="falcon">for i in [1:101]
switch i % 15
switch i % 15
case 0 : > "FizzBuzz"
case 0 : > "FizzBuzz"
Line 3,761: Line 3,761:
default : > i
default : > i
end
end
end</lang>
end</syntaxhighlight>


=={{header|FALSE}}==
=={{header|FALSE}}==
Line 3,767: Line 3,767:


=={{header|Fantom}}==
=={{header|Fantom}}==
<lang fantom>class FizzBuzz
<syntaxhighlight lang="fantom">class FizzBuzz
{
{
public static Void main ()
public static Void main ()
Line 3,783: Line 3,783:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|FBSL}}==
=={{header|FBSL}}==
'''No 'MOD 15' needed.'''
'''No 'MOD 15' needed.'''
<lang qbasic>#APPTYPE CONSOLE
<syntaxhighlight lang="qbasic">#APPTYPE CONSOLE


DIM numbers AS STRING
DIM numbers AS STRING
Line 3,803: Line 3,803:
NEXT
NEXT


PAUSE</lang>
PAUSE</syntaxhighlight>
{{out}}
{{out}}
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fiz
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fiz
Line 3,814: Line 3,814:


=={{header|Fennel}}==
=={{header|Fennel}}==
<lang fennel>(for [i 1 100]
<syntaxhighlight lang="fennel">(for [i 1 100]
(print (if (= (% i 15) 0) :FizzBuzz
(print (if (= (% i 15) 0) :FizzBuzz
(= (% i 3) 0) :Fizz
(= (% i 3) 0) :Fizz
(= (% i 5) 0) :Buzz
(= (% i 5) 0) :Buzz
i)))</lang>
i)))</syntaxhighlight>
Use pattern matching and recursive function:
Use pattern matching and recursive function:
<lang fennel>(fn fizz-buzz [from to]
<syntaxhighlight lang="fennel">(fn fizz-buzz [from to]
(print (match [(% from 3) (% from 5)]
(print (match [(% from 3) (% from 5)]
[0 0] :FizzBuzz
[0 0] :FizzBuzz
Line 3,829: Line 3,829:
(fizz-buzz (+ from 1) to)))
(fizz-buzz (+ from 1) to)))


(fizz-buzz 1 100)</lang>
(fizz-buzz 1 100)</syntaxhighlight>
Alternative matching pattern:{{trans|D}}
Alternative matching pattern:{{trans|D}}
<lang fennel>(for [i 1 100]
<syntaxhighlight lang="fennel">(for [i 1 100]
(print (match (% i 15)
(print (match (% i 15)
0 :FizzBuzz
0 :FizzBuzz
(where (or 3 6 9 12)) :Fizz
(where (or 3 6 9 12)) :Fizz
(where (or 5 10) :Buzz
(where (or 5 10) :Buzz
_ i)))</lang>
_ i)))</syntaxhighlight>


=={{header|FOCAL}}==
=={{header|FOCAL}}==
<tt>FITR</tt> is a built-in function that truncates a floating-point number to an integer. Note that FOCAL uses an arithmetic (three-way) <tt>IF</tt> statement, rather like early Fortran.
<tt>FITR</tt> is a built-in function that truncates a floating-point number to an integer. Note that FOCAL uses an arithmetic (three-way) <tt>IF</tt> statement, rather like early Fortran.
<lang focal>01.10 FOR I=1,100; DO 2.0
<syntaxhighlight lang="focal">01.10 FOR I=1,100; DO 2.0
01.20 QUIT
01.20 QUIT


Line 3,855: Line 3,855:
02.90 TYPE "Buzz" !
02.90 TYPE "Buzz" !
02.95 RETURN
02.95 RETURN
02.99 TYPE %3, I, !</lang>
02.99 TYPE %3, I, !</syntaxhighlight>


=={{header|Fermat}}==
=={{header|Fermat}}==
<lang fermat>
<syntaxhighlight lang="fermat">
for i = 1 to 100 do if i|15=0 then !'FizzBuzz ' else if i|5=0 then !'Buzz ' else if i|3=0 then !'Fizz ' else !i;!' ' fi fi fi od</lang>
for i = 1 to 100 do if i|15=0 then !'FizzBuzz ' else if i|5=0 then !'Buzz ' else if i|3=0 then !'Fizz ' else !i;!' ' fi fi fi od</syntaxhighlight>
{{out}}<pre>
{{out}}<pre>
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fizz 64 Buzz Fizz 67 68 Fizz Buzz 71 Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 82 83 Fizz Buzz 86 Fizz 88 89 FizzBuzz 91 92 Fizz 94 Buzz Fizz 97 98 Fizz Buzz</pre>
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fizz 64 Buzz Fizz 67 68 Fizz Buzz 71 Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 82 83 Fizz Buzz 86 Fizz 88 89 FizzBuzz 91 92 Fizz 94 Buzz Fizz 97 98 Fizz Buzz</pre>
Line 3,865: Line 3,865:
=={{header|Forth}}==
=={{header|Forth}}==
===table-driven===
===table-driven===
<lang forth>: fizz ( n -- ) drop ." Fizz" ;
<syntaxhighlight lang="forth">: fizz ( n -- ) drop ." Fizz" ;
: buzz ( n -- ) drop ." Buzz" ;
: buzz ( n -- ) drop ." Buzz" ;
: fb ( n -- ) drop ." FizzBuzz" ;
: fb ( n -- ) drop ." FizzBuzz" ;
Line 3,875: Line 3,875:
' fizz , ' . , ' . ,
' fizz , ' . , ' . ,
' fizz , ' buzz , ' . ,
' fizz , ' buzz , ' . ,
' fizz , ' . , ' . ,</lang>
' fizz , ' . , ' . ,</syntaxhighlight>
===or the classic approach===
===or the classic approach===
<lang forth>: .fizzbuzz ( n -- )
<syntaxhighlight lang="forth">: .fizzbuzz ( n -- )
0 pad c!
0 pad c!
dup 3 mod 0= if s" Fizz" pad place then
dup 3 mod 0= if s" Fizz" pad place then
Line 3,885: Line 3,885:
: zz ( n -- )
: zz ( n -- )
1+ 1 do i .fizzbuzz cr loop ;
1+ 1 do i .fizzbuzz cr loop ;
100 zz</lang>
100 zz</syntaxhighlight>
===the well factored approach===
===the well factored approach===
SYNONYM is a Forth200x word.
SYNONYM is a Forth200x word.


<lang forth>SYNONYM NOT INVERT \ Bitwise boolean not
<syntaxhighlight lang="forth">SYNONYM NOT INVERT \ Bitwise boolean not


: Fizz? ( n -- ? ) 3 MOD 0= DUP IF ." Fizz" THEN ;
: Fizz? ( n -- ? ) 3 MOD 0= DUP IF ." Fizz" THEN ;
Line 3,897: Line 3,897:
101 1 DO CR I DUP Fizz? OVER Buzz? OR NOT ?print LOOP ;
101 1 DO CR I DUP Fizz? OVER Buzz? OR NOT ?print LOOP ;


FizzBuzz</lang>
FizzBuzz</syntaxhighlight>
===the unrolled approach===
===the unrolled approach===
<lang forth>: n ( n -- n+1 ) dup . 1+ ;
<syntaxhighlight lang="forth">: n ( n -- n+1 ) dup . 1+ ;
: f ( n -- n+1 ) ." Fizz " 1+ ;
: f ( n -- n+1 ) ." Fizz " 1+ ;
: b ( n -- n+1 ) ." Buzz " 1+ ;
: b ( n -- n+1 ) ." Buzz " 1+ ;
Line 3,906: Line 3,906:
: fb15 ( n -- n+15 ) fb10 n f n n fb ;
: fb15 ( n -- n+15 ) fb10 n f n n fb ;
: fb100 ( n -- n+100 ) fb15 fb15 fb15 fb15 fb15 fb15 fb10 ;
: fb100 ( n -- n+100 ) fb15 fb15 fb15 fb15 fb15 fb15 fb10 ;
: .fizzbuzz ( -- ) 1 fb100 drop ;</lang>
: .fizzbuzz ( -- ) 1 fb100 drop ;</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
In ANSI FORTRAN 77 or later use structured IF-THEN-ELSE (example uses some ISO Fortran 90 features):
In ANSI FORTRAN 77 or later use structured IF-THEN-ELSE (example uses some ISO Fortran 90 features):
<lang fortran>program fizzbuzz_if
<syntaxhighlight lang="fortran">program fizzbuzz_if
integer :: i
integer :: i
Line 3,920: Line 3,920:
end if
end if
end do
end do
end program fizzbuzz_if</lang>
end program fizzbuzz_if</syntaxhighlight>
This example uses If statements to print "Fizz" and "Buzz" next to each other if the number is divisible by 3 and 5 by waiting to use a line break until after the If statements.
This example uses If statements to print "Fizz" and "Buzz" next to each other if the number is divisible by 3 and 5 by waiting to use a line break until after the If statements.
<lang fortran>program FizzBuzz
<syntaxhighlight lang="fortran">program FizzBuzz
implicit none
implicit none
integer :: i = 1
integer :: i = 1
Line 3,933: Line 3,933:
end do
end do
end program FizzBuzz
end program FizzBuzz
</syntaxhighlight>
</lang>
In ISO Fortran 90 or later use SELECT-CASE statement:
In ISO Fortran 90 or later use SELECT-CASE statement:
<lang fortran>program fizzbuzz_select
<syntaxhighlight lang="fortran">program fizzbuzz_select
integer :: i
integer :: i
Line 3,946: Line 3,946:
end select
end select
end do
end do
end program fizzbuzz_select</lang>
end program fizzbuzz_select</syntaxhighlight>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
Line 3,952: Line 3,952:


=={{header|Frege}}==
=={{header|Frege}}==
<lang Frege>gen n word = cycle (take (n - 1) (repeat "") ++ [word])
<syntaxhighlight lang="frege">gen n word = cycle (take (n - 1) (repeat "") ++ [word])
pattern = zipWith (++) (gen 3 "fizz") (gen 5 "buzz")
pattern = zipWith (++) (gen 3 "fizz") (gen 5 "buzz")
fizzbuzz = zipWith combine pattern [1..] where
fizzbuzz = zipWith combine pattern [1..] where
Line 3,958: Line 3,958:
then show number
then show number
else word
else word
show $ take 100 fizzbuzz</lang>
show $ take 100 fizzbuzz</syntaxhighlight>


=={{header|Frink}}==
=={{header|Frink}}==
<lang frink>for i = 1 to 100
<syntaxhighlight lang="frink">for i = 1 to 100
{
{
flag = false
flag = false
Line 3,980: Line 3,980:


println[]
println[]
}</lang>
}</syntaxhighlight>


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
<lang futurebasic>include "NSLog.incl"
<syntaxhighlight lang="futurebasic">include "NSLog.incl"


long fizz, buzz, i
long fizz, buzz, i
Line 3,996: Line 3,996:
next i
next i


HandleEvents</lang>
HandleEvents</syntaxhighlight>


Output:
Output:
Line 4,112: Line 4,112:
=={{header|Gambas}}==
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=efbe83377a1eabe475d8eba13965cfde Click this link to run this code]'''
'''[https://gambas-playground.proko.eu/?gist=efbe83377a1eabe475d8eba13965cfde Click this link to run this code]'''
<lang gambas>Public Sub Main()
<syntaxhighlight lang="gambas">Public Sub Main()
Dim siCount As Short
Dim siCount As Short
Dim sText As String
Dim sText As String
Line 4,124: Line 4,124:
Next
Next


End</lang>
End</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 4,230: Line 4,230:


=={{header|GAP}}==
=={{header|GAP}}==
<lang gap>FizzBuzz := function()
<syntaxhighlight lang="gap">FizzBuzz := function()
local i;
local i;
for i in [1 .. 100] do
for i in [1 .. 100] do
Line 4,243: Line 4,243:
fi;
fi;
od;
od;
end;</lang>
end;</syntaxhighlight>


=={{header|Genyris}}==
=={{header|Genyris}}==
<syntaxhighlight lang="genyris">
<lang Genyris>
@prefix u "http://www.genyris.org/lang/utilities#"
@prefix u "http://www.genyris.org/lang/utilities#"


Line 4,268: Line 4,268:
fb
fb


</syntaxhighlight>
</lang>


=={{header|GFA Basic}}==
=={{header|GFA Basic}}==


<lang>
<syntaxhighlight lang="text">
' Fizz Buzz
' Fizz Buzz
'
'
Line 4,286: Line 4,286:
ENDIF
ENDIF
NEXT i%
NEXT i%
</syntaxhighlight>
</lang>


=={{header|Gleam}}==
=={{header|Gleam}}==


<lang>import gleam/int
<syntaxhighlight lang="text">import gleam/int
import gleam/io
import gleam/io
import gleam/iterator
import gleam/iterator
Line 4,308: Line 4,308:
_, _ -> int.to_string(n)
_, _ -> int.to_string(n)
}
}
}</lang>
}</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
===switch/case approach===
===switch/case approach===
<lang go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 4,329: Line 4,329:
}
}
}
}
}</lang>
}</syntaxhighlight>
===map approach===
===map approach===
<lang go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 4,341: Line 4,341:
}[i%5 == 0][i%3 == 0])
}[i%5 == 0][i%3 == 0])
}
}
}</lang>
}</syntaxhighlight>


=={{header|Golfscript}}==
=={{header|Golfscript}}==
<lang golfscript>100,{)6,{.(&},{1$1$%{;}{4*35+6875*25base{90\-}%}if}%\or}%n*</lang>
<syntaxhighlight lang="golfscript">100,{)6,{.(&},{1$1$%{;}{4*35+6875*25base{90\-}%}if}%\or}%n*</syntaxhighlight>


=={{header|Golo}}==
=={{header|Golo}}==
<lang golo>module FizzBuzz
<syntaxhighlight lang="golo">module FizzBuzz


augment java.lang.Integer {
augment java.lang.Integer {
Line 4,363: Line 4,363:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Gosu}}==
=={{header|Gosu}}==
<lang gosu>for (i in 1..100) {
<syntaxhighlight lang="gosu">for (i in 1..100) {
if (i % 3 == 0 && i % 5 == 0) {
if (i % 3 == 0 && i % 5 == 0) {
Line 4,386: Line 4,386:
print(i)
print(i)
}</lang>
}</syntaxhighlight>
One liner version (I added new lines to better readability but when you omit them it's one liner):
One liner version (I added new lines to better readability but when you omit them it's one liner):
<lang gosu>// note that compiler reports error (I don't know why) but still it's working
<syntaxhighlight lang="gosu">// note that compiler reports error (I don't know why) but still it's working
for (i in 1..100) {
for (i in 1..100) {
print(i % 5 == 0 ? i % 3 == 0 ? "FizzBuzz" : "Buzz" : i % 3 == 0 ? "Fizz" : i)
print(i % 5 == 0 ? i % 3 == 0 ? "FizzBuzz" : "Buzz" : i % 3 == 0 ? "Fizz" : i)
}</lang>
}</syntaxhighlight>


=={{header|Groovy}}==
=={{header|Groovy}}==
<lang groovy>1.upto(100) { i -> println "${i % 3 ? '' : 'Fizz'}${i % 5 ? '' : 'Buzz'}" ?: i }</lang>
<syntaxhighlight lang="groovy">1.upto(100) { i -> println "${i % 3 ? '' : 'Fizz'}${i % 5 ? '' : 'Buzz'}" ?: i }</syntaxhighlight>


=={{header|GW-BASIC}}==
=={{header|GW-BASIC}}==
Line 4,400: Line 4,400:


=={{header|Hare}}==
=={{header|Hare}}==
<lang hare>
<syntaxhighlight lang="hare">
use fmt;
use fmt;


Line 4,413: Line 4,413:
};
};
};
};
</syntaxhighlight>
</lang>


=={{header|Haskell}}==
=={{header|Haskell}}==
Variant directly implementing the specification:
Variant directly implementing the specification:
<lang haskell>fizzbuzz :: Int -> String
<syntaxhighlight lang="haskell">fizzbuzz :: Int -> String
fizzbuzz x
fizzbuzz x
| f 15 = "FizzBuzz"
| f 15 = "FizzBuzz"
Line 4,427: Line 4,427:


main :: IO ()
main :: IO ()
main = mapM_ (putStrLn . fizzbuzz) [1 .. 100]</lang>
main = mapM_ (putStrLn . fizzbuzz) [1 .. 100]</syntaxhighlight>


<lang haskell>fizzbuzz :: Int -> String
<syntaxhighlight lang="haskell">fizzbuzz :: Int -> String
fizzbuzz n =
fizzbuzz n =
'\n' :
'\n' :
Line 4,446: Line 4,446:


main :: IO ()
main :: IO ()
main = putStr $ concatMap fizzbuzz [1 .. 100]</lang>
main = putStr $ concatMap fizzbuzz [1 .. 100]</syntaxhighlight>
Does not perform the mod 15 step, extesible to arbitrary addtional tests, ex: [bar| n `mod` 7 == 0].
Does not perform the mod 15 step, extesible to arbitrary addtional tests, ex: [bar| n `mod` 7 == 0].
<lang haskell>main = mapM_ (putStrLn . fizzbuzz) [1..100]
<syntaxhighlight lang="haskell">main = mapM_ (putStrLn . fizzbuzz) [1..100]


fizzbuzz n =
fizzbuzz n =
Line 4,461: Line 4,461:


fizz = "Fizz"
fizz = "Fizz"
buzz = "Buzz"</lang>
buzz = "Buzz"</syntaxhighlight>
Alternate implementation using lazy infinite lists and avoiding use of "mod":
Alternate implementation using lazy infinite lists and avoiding use of "mod":
<lang haskell>main = mapM_ putStrLn $ take 100 $ zipWith show_number_or_fizzbuzz [1..] fizz_buzz_list
<syntaxhighlight lang="haskell">main = mapM_ putStrLn $ take 100 $ zipWith show_number_or_fizzbuzz [1..] fizz_buzz_list


show_number_or_fizzbuzz x y = if null y then show x else y
show_number_or_fizzbuzz x y = if null y then show x else y


fizz_buzz_list = zipWith (++) (cycle ["","","Fizz"]) (cycle ["","","","","Buzz"])</lang>
fizz_buzz_list = zipWith (++) (cycle ["","","Fizz"]) (cycle ["","","","","Buzz"])</syntaxhighlight>


Or in terms (still without '''mod''' or '''rem''') of a single '''zipWith3''':
Or in terms (still without '''mod''' or '''rem''') of a single '''zipWith3''':
<lang haskell>import Data.List (zipWith3)
<syntaxhighlight lang="haskell">import Data.List (zipWith3)
import Data.Bool (bool)
import Data.Bool (bool)


Line 4,484: Line 4,484:


main :: IO ()
main :: IO ()
main = mapM_ putStrLn $ take 100 fizzBuzz</lang>
main = mapM_ putStrLn $ take 100 fizzBuzz</syntaxhighlight>


or using an applicative test:
or using an applicative test:


<lang haskell>import Data.Bool (bool)
<syntaxhighlight lang="haskell">import Data.Bool (bool)


fizzBuzz :: [String]
fizzBuzz :: [String]
Line 4,500: Line 4,500:
main :: IO ()
main :: IO ()
main = mapM_ putStrLn $ take 100 fizzBuzz
main = mapM_ putStrLn $ take 100 fizzBuzz
</syntaxhighlight>
</lang>


Using heavy artillery (needs the mtl package):
Using heavy artillery (needs the mtl package):
<lang haskell>
<syntaxhighlight lang="haskell">
import Control.Monad.State
import Control.Monad.State
import Control.Monad.Trans
import Control.Monad.Trans
Line 4,515: Line 4,515:
when (x `mod` 5 == 0) $ tell "Buzz" >> put False
when (x `mod` 5 == 0) $ tell "Buzz" >> put False
get >>= (flip when $ tell $ show x)
get >>= (flip when $ tell $ show x)
tell "\n"</lang>
tell "\n"</syntaxhighlight>
Using guards plus where.
Using guards plus where.
<lang haskell>fizzBuzz :: (Integral a) => a -> String
<syntaxhighlight lang="haskell">fizzBuzz :: (Integral a) => a -> String
fizzBuzz i
fizzBuzz i
| fizz && buzz = "FizzBuzz"
| fizz && buzz = "FizzBuzz"
Line 4,526: Line 4,526:
buzz = i `mod` 5 == 0
buzz = i `mod` 5 == 0


main = mapM_ (putStrLn . fizzBuzz) [1..100]</lang>
main = mapM_ (putStrLn . fizzBuzz) [1..100]</syntaxhighlight>


An elegant solution exploiting monoidal and applicative properties of functions:
An elegant solution exploiting monoidal and applicative properties of functions:
<lang haskell>import Data.Monoid
<syntaxhighlight lang="haskell">import Data.Monoid


fizzbuzz = max
fizzbuzz = max
Line 4,540: Line 4,540:
divisibleBy n x = x `mod` n == 0
divisibleBy n x = x `mod` n == 0


main = mapM_ (putStrLn . fizzbuzz) [1..100]</lang>
main = mapM_ (putStrLn . fizzbuzz) [1..100]</syntaxhighlight>


And pattern matching approach:
And pattern matching approach:
<lang haskell>fizzbuzz n = case (rem n 3, rem n 5) of
<syntaxhighlight lang="haskell">fizzbuzz n = case (rem n 3, rem n 5) of
(0, 0) -> "FizzBuzz"
(0, 0) -> "FizzBuzz"
(0, _) -> "Fizz"
(0, _) -> "Fizz"
Line 4,549: Line 4,549:
(_, _) -> show n
(_, _) -> show n


main = mapM_ (putStrLn . fizzbuzz) [1..100]</lang>
main = mapM_ (putStrLn . fizzbuzz) [1..100]</syntaxhighlight>


Generalised solution:
Generalised solution:
<lang haskell>wordthing :: [(Int, String)] -> Int -> String
<syntaxhighlight lang="haskell">wordthing :: [(Int, String)] -> Int -> String
wordthing lst n =
wordthing lst n =
if matches == [] then
if matches == [] then
Line 4,564: Line 4,564:


main = do
main = do
mapM_ (putStrLn . fizzbuzz) [1..100]</lang>
mapM_ (putStrLn . fizzbuzz) [1..100]</syntaxhighlight>


=={{header|hexiscript}}==
=={{header|hexiscript}}==
<lang hexiscript>for let i 1; i <= 100; i++
<syntaxhighlight lang="hexiscript">for let i 1; i <= 100; i++
if i % 3 = 0 && i % 5 = 0; println "FizzBuzz"
if i % 3 = 0 && i % 5 = 0; println "FizzBuzz"
elif i % 3 = 0; println "Fizz"
elif i % 3 = 0; println "Fizz"
elif i % 5 = 0; println "Buzz"
elif i % 5 = 0; println "Buzz"
else println i; endif
else println i; endif
endfor</lang>
endfor</syntaxhighlight>


=={{header|HicEst}}==
=={{header|HicEst}}==
<lang hicest>DO i = 1, 100
<syntaxhighlight lang="hicest">DO i = 1, 100
IF( MOD(i, 15) == 0 ) THEN
IF( MOD(i, 15) == 0 ) THEN
WRITE() "FizzBuzz"
WRITE() "FizzBuzz"
Line 4,585: Line 4,585:
WRITE() i
WRITE() i
ENDIF
ENDIF
ENDDO</lang>
ENDDO</syntaxhighlight>
Alternatively:
Alternatively:
<lang hicest>CHARACTER string*8
<syntaxhighlight lang="hicest">CHARACTER string*8


DO i = 1, 100
DO i = 1, 100
Line 4,595: Line 4,595:
IF( string == " ") WRITE(Text=string) i
IF( string == " ") WRITE(Text=string) i
WRITE() string
WRITE() string
ENDDO</lang>
ENDDO</syntaxhighlight>


=={{header|HolyC}}==
=={{header|HolyC}}==
<lang holyc>U8 i;
<syntaxhighlight lang="holyc">U8 i;
for (i = 1; i <= 100; i++) {
for (i = 1; i <= 100; i++) {
if (!(i % 15))
if (!(i % 15))
Line 4,609: Line 4,609:
Print("%d", i);
Print("%d", i);
Print("\n");
Print("\n");
}</lang>
}</syntaxhighlight>


=={{header|Hoon}}==
=={{header|Hoon}}==
<lang Hoon>:- %say
<syntaxhighlight lang="hoon">:- %say
|= [^ ~ ~]
|= [^ ~ ~]
:- %noun
:- %noun
Line 4,622: Line 4,622:
[& |] "Fizz"
[& |] "Fizz"
[| &] "Buzz"
[| &] "Buzz"
==</lang>
==</syntaxhighlight>


=={{header|Huginn}}==
=={{header|Huginn}}==
<lang huginn>import Algorithms as algo;
<syntaxhighlight lang="huginn">import Algorithms as algo;


main( argv_ ) {
main( argv_ ) {
Line 4,647: Line 4,647:
}
}
return ( 0 );
return ( 0 );
}</lang>
}</syntaxhighlight>


=={{header|Hy}}==
=={{header|Hy}}==


<lang lisp>(for [i (range 1 101)] (print (cond
<syntaxhighlight lang="lisp">(for [i (range 1 101)] (print (cond
[(not (% i 15)) "FizzBuzz"]
[(not (% i 15)) "FizzBuzz"]
[(not (% i 5)) "Buzz"]
[(not (% i 5)) "Buzz"]
[(not (% i 3)) "Fizz"]
[(not (% i 3)) "Fizz"]
[True i])))</lang>
[True i])))</syntaxhighlight>


=={{header|i}}==
=={{header|i}}==
<lang i>software {
<syntaxhighlight lang="i">software {
for each 1 to 100
for each 1 to 100
if i % 15 = 0
if i % 15 = 0
Line 4,670: Line 4,670:
end
end
end
end
}</lang>
}</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
<lang icon># straight-forward modulo tester
<syntaxhighlight lang="icon"># straight-forward modulo tester
procedure main()
procedure main()
every i := 1 to 100 do
every i := 1 to 100 do
Line 4,684: Line 4,684:
else
else
write(i)
write(i)
end</lang>
end</syntaxhighlight>
<lang icon># idiomatic modulo tester, 1st alternative
<syntaxhighlight lang="icon"># idiomatic modulo tester, 1st alternative
procedure main()
procedure main()
every i := 1 to 100 do
every i := 1 to 100 do
write((i % 15 = 0 & "FizzBuzz") | (i % 5 = 0 & "Buzz") | (i % 3 = 0 & "Fizz") | i)
write((i % 15 = 0 & "FizzBuzz") | (i % 5 = 0 & "Buzz") | (i % 3 = 0 & "Fizz") | i)
end</lang>
end</syntaxhighlight>
<lang icon># idiomatic modulo tester, 2nd alternative
<syntaxhighlight lang="icon"># idiomatic modulo tester, 2nd alternative
procedure main()
procedure main()
every i := 1 to 100 do
every i := 1 to 100 do
Line 4,699: Line 4,699:
default: i
default: i
})
})
end</lang>
end</syntaxhighlight>
<lang icon># straight-forward buffer builder
<syntaxhighlight lang="icon"># straight-forward buffer builder
procedure main()
procedure main()
every i := 1 to 100 do {
every i := 1 to 100 do {
Line 4,712: Line 4,712:
write(s)
write(s)
}
}
end</lang>
end</syntaxhighlight>
<lang icon># idiomatic buffer builder, 1st alternative
<syntaxhighlight lang="icon"># idiomatic buffer builder, 1st alternative
procedure main()
procedure main()
every i := 1 to 100 do
every i := 1 to 100 do
write("" ~== (if i % 3 = 0 then "Fizz" else "") || (if i % 5 == 0 then "Buzz" else "") | i)
write("" ~== (if i % 3 = 0 then "Fizz" else "") || (if i % 5 == 0 then "Buzz" else "") | i)
end</lang>
end</syntaxhighlight>
<lang icon># idiomatic buffer builder, 2nd alternative
<syntaxhighlight lang="icon"># idiomatic buffer builder, 2nd alternative
procedure main()
procedure main()
every i := 1 to 100 do {
every i := 1 to 100 do {
Line 4,725: Line 4,725:
write(("" ~= s) | i)
write(("" ~= s) | i)
}
}
end</lang>
end</syntaxhighlight>


=={{header|Idris}}==
=={{header|Idris}}==
<lang idris>partial
<syntaxhighlight lang="idris">partial
fizzBuzz : Nat -> String
fizzBuzz : Nat -> String
fizzBuzz n = if (n `modNat` 15) == 0 then "FizzBuzz"
fizzBuzz n = if (n `modNat` 15) == 0 then "FizzBuzz"
Line 4,736: Line 4,736:


main : IO ()
main : IO ()
main = sequence_ $ map (putStrLn . fizzBuzz) [1..100]</lang>
main = sequence_ $ map (putStrLn . fizzBuzz) [1..100]</syntaxhighlight>


=={{header|Inform 6}}==
=={{header|Inform 6}}==
<lang inform6>[ Main i;
<syntaxhighlight lang="inform6">[ Main i;
for(i = 1: i <= 100: i++)
for(i = 1: i <= 100: i++)
{
{
Line 4,748: Line 4,748:
print "^";
print "^";
}
}
];</lang>
];</syntaxhighlight>


=={{header|Inform 7}}==
=={{header|Inform 7}}==
Line 4,754: Line 4,754:
(Does not work in the current version of Inform 7)
(Does not work in the current version of Inform 7)


<lang inform7>Home is a room.
<syntaxhighlight lang="inform7">Home is a room.


When play begins:
When play begins:
Line 4,767: Line 4,767:
if printed is false, say N;
if printed is false, say N;
say ".";
say ".";
end the story.</lang>
end the story.</syntaxhighlight>


(Version which is less "programmy", and more in the natural English style of interactive fiction.)
(Version which is less "programmy", and more in the natural English style of interactive fiction.)


<lang inform7>The space is a room. An item is a kind of thing. In the space are 100 items.
<syntaxhighlight lang="inform7">The space is a room. An item is a kind of thing. In the space are 100 items.


To say the name:
To say the name:
Line 4,786: Line 4,786:
end if.
end if.
When play begins: count. Use no scoring.</lang>
When play begins: count. Use no scoring.</syntaxhighlight>


=={{header|Io}}==
=={{header|Io}}==
Here's one way to do it:
Here's one way to do it:
<lang io>for(a,1,100,
<syntaxhighlight lang="io">for(a,1,100,
if(a % 15 == 0) then(
if(a % 15 == 0) then(
"FizzBuzz" println
"FizzBuzz" println
Line 4,800: Line 4,800:
a println
a println
)
)
)</lang>
)</syntaxhighlight>
And here's a port of the Ruby version, which I personally prefer:
And here's a port of the Ruby version, which I personally prefer:
<lang io>a := 0; b := 0
<syntaxhighlight lang="io">a := 0; b := 0
for(n, 1, 100,
for(n, 1, 100,
if(a = (n % 3) == 0, "Fizz" print);
if(a = (n % 3) == 0, "Fizz" print);
Line 4,808: Line 4,808:
if(a not and b not, n print);
if(a not and b not, n print);
"\n" print
"\n" print
)</lang>
)</syntaxhighlight>
And here is another more idiomatic version:
And here is another more idiomatic version:
<lang Io>for (n, 1, 100,
<syntaxhighlight lang="io">for (n, 1, 100,
fb := list (
fb := list (
if (n % 3 == 0, "Fizz"),
if (n % 3 == 0, "Fizz"),
Line 4,816: Line 4,816:
if (fb isEmpty, n, fb join) println
if (fb isEmpty, n, fb join) println
)</lang>
)</syntaxhighlight>


=={{header|Ioke}}==
=={{header|Ioke}}==
<lang ioke>(1..100) each(x,
<syntaxhighlight lang="ioke">(1..100) each(x,
cond(
cond(
(x % 15) zero?, "FizzBuzz" println,
(x % 15) zero?, "FizzBuzz" println,
Line 4,825: Line 4,825:
(x % 5) zero?, "Buzz" println
(x % 5) zero?, "Buzz" println
)
)
)</lang>
)</syntaxhighlight>


=={{header|Iptscrae}}==
=={{header|Iptscrae}}==
<lang iptscrae>; FizzBuzz in Iptscrae
<syntaxhighlight lang="iptscrae">; FizzBuzz in Iptscrae
1 a =
1 a =
{
{
Line 4,837: Line 4,837:
a ++
a ++
}
}
{ a 100 <= } WHILE</lang>
{ a 100 <= } WHILE</syntaxhighlight>


=={{header|J}}==
=={{header|J}}==
Line 4,848: Line 4,848:


Solution _1: Using agenda (@.) as a switch:
Solution _1: Using agenda (@.) as a switch:
<syntaxhighlight lang="j">
<lang j>
classify =: +/@(1 2 * 0 = 3 5&|~)
classify =: +/@(1 2 * 0 = 3 5&|~)
(":@]`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_) @. classify "0) >:i.100
(":@]`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_) @. classify "0) >:i.100
</syntaxhighlight>
</lang>
Solution 0
Solution 0
<lang j>> }. (<'FizzBuzz') (I.0=15|n)} (<'Buzz') (I.0=5|n)} (<'Fizz') (I.0=3|n)} ":&.> n=: i.101</lang>
<syntaxhighlight lang="j">> }. (<'FizzBuzz') (I.0=15|n)} (<'Buzz') (I.0=5|n)} (<'Fizz') (I.0=3|n)} ":&.> n=: i.101</syntaxhighlight>
Solution 1
Solution 1
<lang j>Fizz=: 'Fizz' #~ 0 = 3&|
<syntaxhighlight lang="j">Fizz=: 'Fizz' #~ 0 = 3&|
Buzz=: 'Buzz' #~ 0 = 5&|
Buzz=: 'Buzz' #~ 0 = 5&|
FizzBuzz=: ": [^:('' -: ]) Fizz,Buzz
FizzBuzz=: ": [^:('' -: ]) Fizz,Buzz


FizzBuzz"0 >: i.100</lang>
FizzBuzz"0 >: i.100</syntaxhighlight>
Solution 2 (has taste of table-driven template programming)
Solution 2 (has taste of table-driven template programming)
<lang j>CRT0=: 2 : ' (, 0 = +./)@(0 = m | ]) ;@# n , <@": '
<syntaxhighlight lang="j">CRT0=: 2 : ' (, 0 = +./)@(0 = m | ]) ;@# n , <@": '
NB. Rather (, 0 = +./) than (, +:/) because designed for
NB. Rather (, 0 = +./) than (, +:/) because designed for
NB. 3 5 7 CRT0 (;:'Chinese Remainder Period') "0 >: i. */3 5 7
NB. 3 5 7 CRT0 (;:'Chinese Remainder Period') "0 >: i. */3 5 7
FizzBuzz=: 3 5 CRT0 (;:'Fizz Buzz')
FizzBuzz=: 3 5 CRT0 (;:'Fizz Buzz')


FizzBuzz"0 >: i.100</lang>
FizzBuzz"0 >: i.100</syntaxhighlight>
Solution 3 (depends on an obsolete feature of @ in f`g`h@p)
Solution 3 (depends on an obsolete feature of @ in f`g`h@p)
<lang j>'`f b fb' =: ('Fizz'"_) ` ('Buzz'"_) ` (f , b)
<syntaxhighlight lang="j">'`f b fb' =: ('Fizz'"_) ` ('Buzz'"_) ` (f , b)
'`cm3 cm5 cm15'=: (3&|) ` (5&|) ` (15&|) (0&=@)
'`cm3 cm5 cm15'=: (3&|) ` (5&|) ` (15&|) (0&=@)
FizzBuzz=: ": ` f @. cm3 ` b @. cm5 ` fb @. cm15 NB. also:
FizzBuzz=: ": ` f @. cm3 ` b @. cm5 ` fb @. cm15 NB. also:
FizzBuzz=: ": ` f @. cm3 ` b @. cm5 ` (f,b) @. (cm3 *. cm5)
FizzBuzz=: ": ` f @. cm3 ` b @. cm5 ` (f,b) @. (cm3 *. cm5)


FizzBuzz"0 >: i.100</lang>
FizzBuzz"0 >: i.100</syntaxhighlight>


Solution 4 (relatively concise):
Solution 4 (relatively concise):


<lang J> ;:inv}.(":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~ 0 = 3 5 |/ ])i.101
<syntaxhighlight lang="j"> ;:inv}.(":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~ 0 = 3 5 |/ ])i.101
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fiz...</lang>
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fiz...</syntaxhighlight>


Here's some intermediate results for subexpressions of this last version (but with a shorter list of numbers):
Here's some intermediate results for subexpressions of this last version (but with a shorter list of numbers):


<lang J> i.10
<syntaxhighlight lang="j"> i.10
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
(3 5 |/ ])i.10
(3 5 |/ ])i.10
Line 4,917: Line 4,917:
└─┴─┴────┴─┴────┴────┴─┴─┴────┘
└─┴─┴────┴─┴────┴────┴─┴─┴────┘
;:inv}.(":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
;:inv}.(":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
1 2 Fizz 4 Buzz Fizz 7 8 Fizz</lang>
1 2 Fizz 4 Buzz Fizz 7 8 Fizz</syntaxhighlight>


=={{header|Janet}}==
=={{header|Janet}}==
<lang janet>
<syntaxhighlight lang="janet">
(loop [i :range [1 101]
(loop [i :range [1 101]
:let [fizz (zero? (% i 3))
:let [fizz (zero? (% i 3))
Line 4,929: Line 4,929:
buzz "buzz"
buzz "buzz"
i)))
i)))
</syntaxhighlight>
</lang>


=={{header|Java}}==
=={{header|Java}}==
<lang java>
<syntaxhighlight lang="java">
public class FizzBuzz {
public class FizzBuzz {
public static void main(String[] args) {
public static void main(String[] args) {
Line 4,948: Line 4,948:
}
}
}
}
</syntaxhighlight>
</lang>
'''Or: '''
'''Or: '''
<lang java>
<syntaxhighlight lang="java">
public class FizzBuzz {
public class FizzBuzz {
public static void main(String[] args) {
public static void main(String[] args) {
Line 4,968: Line 4,968:
}
}
}
}
</syntaxhighlight>
</lang>
'''Or: '''
'''Or: '''
<lang java>
<syntaxhighlight lang="java">
public class FizzBuzz {
public class FizzBuzz {
public static void main(String[] args) {
public static void main(String[] args) {
Line 4,980: Line 4,980:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
Line 4,986: Line 4,986:
===ES5===
===ES5===


<lang javascript>var fizzBuzz = function () {
<syntaxhighlight lang="javascript">var fizzBuzz = function () {
var i, output;
var i, output;
for (i = 1; i < 101; i += 1) {
for (i = 1; i < 101; i += 1) {
Line 4,994: Line 4,994:
console.log(output || i);//empty string is false, so we short-circuit
console.log(output || i);//empty string is false, so we short-circuit
}
}
};</lang>
};</syntaxhighlight>


Alternate version with ghetto pattern matching
Alternate version with ghetto pattern matching
<lang javascript>for (var i = 1; i <= 100; i++) {
<syntaxhighlight lang="javascript">for (var i = 1; i <= 100; i++) {
console.log({
console.log({
truefalse: 'Fizz',
truefalse: 'Fizz',
Line 5,003: Line 5,003:
truetrue: 'FizzBuzz'
truetrue: 'FizzBuzz'
}[(i%3==0) + '' + (i%5==0)] || i)
}[(i%3==0) + '' + (i%5==0)] || i)
}</lang>
}</syntaxhighlight>


Or very tersely:
Or very tersely:
<lang javascript>for(i=1;i<101;i++)console.log((x=(i%3?'':'Fizz')+(i%5?'':'Buzz'))?x:i);</lang>
<syntaxhighlight lang="javascript">for(i=1;i<101;i++)console.log((x=(i%3?'':'Fizz')+(i%5?'':'Buzz'))?x:i);</syntaxhighlight>


Or with even less characters:
Or with even less characters:
<lang javascript>for(i=1;i<101;i++)console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)</lang>
<syntaxhighlight lang="javascript">for(i=1;i<101;i++)console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)</syntaxhighlight>


Or, in a more functional style, without mutations
Or, in a more functional style, without mutations
<lang javascript>(function rng(i) {
<syntaxhighlight lang="javascript">(function rng(i) {
return i ? rng(i - 1).concat(i) : []
return i ? rng(i - 1).concat(i) : []
})(100).map(
})(100).map(
Line 5,022: Line 5,022:
)
)
}
}
).join(' ')</lang>
).join(' ')</syntaxhighlight>


===ES6===
===ES6===
<lang JavaScript>(() => {
<syntaxhighlight lang="javascript">(() => {


// FIZZBUZZ --------------------------------------------------------------
// FIZZBUZZ --------------------------------------------------------------
Line 5,060: Line 5,060:
map(fizzBuzz, enumFromTo(1, 100))
map(fizzBuzz, enumFromTo(1, 100))
);
);
})();</lang>
})();</syntaxhighlight>


A functional implementation:
A functional implementation:


<lang Javascript>const factors = [[3, 'Fizz'], [5, 'Buzz']]
<syntaxhighlight lang="javascript">const factors = [[3, 'Fizz'], [5, 'Buzz']]
const fizzBuzz = num => factors.map(([factor,text]) => (num % factor)?'':text).join('') || num
const fizzBuzz = num => factors.map(([factor,text]) => (num % factor)?'':text).join('') || num
const range1 = x => [...Array(x+1).keys()].slice(1)
const range1 = x => [...Array(x+1).keys()].slice(1)
const outputs = range1(100).map(fizzBuzz)
const outputs = range1(100).map(fizzBuzz)


console.log(outputs.join('\n'))</lang>
console.log(outputs.join('\n'))</syntaxhighlight>




Line 5,075: Line 5,075:
{{Trans|Python}}
{{Trans|Python}}
{{Trans|Haskell}}
{{Trans|Haskell}}
<lang javascript>(() => {
<syntaxhighlight lang="javascript">(() => {
'use strict';
'use strict';


Line 5,259: Line 5,259:
// MAIN ---
// MAIN ---
return main();
return main();
})();</lang>
})();</syntaxhighlight>


=={{header|Joy}}==
=={{header|Joy}}==
The following program first defines a function "out", that handles the Fizz / Buzz logic, and then loops from 1 to 100 mapping the function onto each number, and printing ("put") the output.
The following program first defines a function "out", that handles the Fizz / Buzz logic, and then loops from 1 to 100 mapping the function onto each number, and printing ("put") the output.
<syntaxhighlight lang=Joy>DEFINE out == [[[15 rem null] "FizzBuzz"]
<syntaxhighlight lang="joy">DEFINE out == [[[15 rem null] "FizzBuzz"]
[[ 3 rem null] "Fizz"]
[[ 3 rem null] "Fizz"]
[[ 5 rem null] "Buzz"]
[[ 5 rem null] "Buzz"]
Line 5,272: Line 5,272:


=={{header|jq}}==
=={{header|jq}}==
<lang jq>range(1;101)
<syntaxhighlight lang="jq">range(1;101)
| if . % 15 == 0 then "FizzBuzz"
| if . % 15 == 0 then "FizzBuzz"
elif . % 5 == 0 then "Buzz"
elif . % 5 == 0 then "Buzz"
elif . % 3 == 0 then "Fizz"
elif . % 3 == 0 then "Fizz"
else .
else .
end</lang>
end</syntaxhighlight>


Another solution:
Another solution:


<lang jq>range(100) + 1 | [(
<syntaxhighlight lang="jq">range(100) + 1 | [(
(select(. % 3 == 0) | "Fizz"),
(select(. % 3 == 0) | "Fizz"),
(select(. % 5 == 0) | "Buzz")
(select(. % 5 == 0) | "Buzz")
) // tostring] | join("")
) // tostring] | join("")
</syntaxhighlight>
</lang>


=={{header|Julia}}==
=={{header|Julia}}==
Line 5,291: Line 5,291:


One basic solution:
One basic solution:
<lang julia>for i in 1:100
<syntaxhighlight lang="julia">for i in 1:100
if i % 15 == 0
if i % 15 == 0
println("FizzBuzz")
println("FizzBuzz")
Line 5,301: Line 5,301:
println(i)
println(i)
end
end
end</lang>
end</syntaxhighlight>


Another possible solution:
Another possible solution:
<lang julia>collect(i % 15 == 0 ? "FizzBuzz" : i % 5 == 0 ? "Buzz" : i % 3 == 0 ? "Fizz" : i for i in 1:100) |> println</lang>
<syntaxhighlight lang="julia">collect(i % 15 == 0 ? "FizzBuzz" : i % 5 == 0 ? "Buzz" : i % 3 == 0 ? "Fizz" : i for i in 1:100) |> println</syntaxhighlight>


A 3rd possible solution:
A 3rd possible solution:
<lang julia>fb(i::Integer) = "Fizz" ^ (i % 3 == 0) * "Buzz" ^ (i % 5 == 0) * dec(i) ^ (i % 3 != 0 && i % 5 != 0)
<syntaxhighlight lang="julia">fb(i::Integer) = "Fizz" ^ (i % 3 == 0) * "Buzz" ^ (i % 5 == 0) * dec(i) ^ (i % 3 != 0 && i % 5 != 0)
for i in 1:100 println(fb(i)) end</lang>
for i in 1:100 println(fb(i)) end</syntaxhighlight>


A 4th one:
A 4th one:
<lang julia>println.(map(fb, 1:100))</lang>
<syntaxhighlight lang="julia">println.(map(fb, 1:100))</syntaxhighlight>


A fifth (DRY, Don't Repeat Yourself) possible solution:
A fifth (DRY, Don't Repeat Yourself) possible solution:
<lang julia>for i in 1:100
<syntaxhighlight lang="julia">for i in 1:100
msg = "Fizz" ^ (i % 3 == 0) * "Buzz" ^ (i % 5 == 0)
msg = "Fizz" ^ (i % 3 == 0) * "Buzz" ^ (i % 5 == 0)
println(isempty(msg) ? i : msg)
println(isempty(msg) ? i : msg)
end</lang>
end</syntaxhighlight>


=={{header|K}}==
=={{header|K}}==
===Solution 0===
===Solution 0===
<lang k>`0:\:{:[0=#a:{,/$(:[0=x!3;"Fizz"];:[0=x!5;"Buzz"])}@x;$x;a]}'1_!101</lang>
<syntaxhighlight lang="k">`0:\:{:[0=#a:{,/$(:[0=x!3;"Fizz"];:[0=x!5;"Buzz"])}@x;$x;a]}'1_!101</syntaxhighlight>


===Solution 1===
===Solution 1===
<syntaxhighlight lang="k">
<lang k>
fizzbuzz:{:[0=x!15;`0:,"FizzBuzz";0=x!3;`0:,"Fizz";0=x!5;`0:,"Buzz";`0:,$x]}
fizzbuzz:{:[0=x!15;`0:,"FizzBuzz";0=x!3;`0:,"Fizz";0=x!5;`0:,"Buzz";`0:,$x]}
fizzbuzz' 1+!100
fizzbuzz' 1+!100
</syntaxhighlight>
</lang>


===Solution 2===
===Solution 2===
<lang k>fizzbuzz:{
<syntaxhighlight lang="k">fizzbuzz:{
v:1+!x
v:1+!x
i:(&0=)'v!/:3 5 15
i:(&0=)'v!/:3 5 15
Line 5,337: Line 5,337:
@[r;i 2;{"FizzBuzz"}]}
@[r;i 2;{"FizzBuzz"}]}


`0:$fizzbuzz 100</lang>
`0:$fizzbuzz 100</syntaxhighlight>


===Solution 3===
===Solution 3===
For kona: <lang k>{,/$(s;x)@~#s:`Fizz`Buzz@&~x!'3 5}'1+!30</lang>
For kona: <syntaxhighlight lang="k">{,/$(s;x)@~#s:`Fizz`Buzz@&~x!'3 5}'1+!30</syntaxhighlight>
For k6 and oK, change <code>x!'3 5</code> to <code>3 5!'x</code>.
For k6 and oK, change <code>x!'3 5</code> to <code>3 5!'x</code>.


Line 5,347: Line 5,347:


This will only work up to 100 because Kamailio terminates all while loops after 100 iterations.
This will only work up to 100 because Kamailio terminates all while loops after 100 iterations.
<lang kamailio># FizzBuzz
<syntaxhighlight lang="kamailio"># FizzBuzz
log_stderror=yes
log_stderror=yes
loadmodule "pv"
loadmodule "pv"
Line 5,366: Line 5,366:
$var(i) = $var(i) + 1;
$var(i) = $var(i) + 1;
}
}
}</lang>
}</syntaxhighlight>


=={{header|Kaya}}==
=={{header|Kaya}}==
<lang kaya>// fizzbuzz in Kaya
<syntaxhighlight lang="kaya">// fizzbuzz in Kaya
program fizzbuzz;
program fizzbuzz;


Line 5,388: Line 5,388:
Void main() {
Void main() {
fizzbuzz(100);
fizzbuzz(100);
}</lang>
}</syntaxhighlight>


=={{header|KL1}}==
=={{header|KL1}}==
<lang prolog>
<syntaxhighlight lang="prolog">
:- module main.
:- module main.


Line 5,429: Line 5,429:
display(Rest).
display(Rest).
display([]).
display([]).
</syntaxhighlight>
</lang>


=={{header|Klong}}==
=={{header|Klong}}==
<syntaxhighlight lang="k">
<lang k>
{:[0=x!15;:FizzBuzz:|0=x!5;:Buzz:|0=x!3;:Fizz;x]}'1+!100
{:[0=x!15;:FizzBuzz:|0=x!5;:Buzz:|0=x!3;:Fizz;x]}'1+!100
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==


===Imperative solution===
===Imperative solution===
<lang scala>fun fizzBuzz() {
<syntaxhighlight lang="scala">fun fizzBuzz() {
for (number in 1..100) {
for (number in 1..100) {
println(
println(
Line 5,450: Line 5,450:
)
)
}
}
}</lang>
}</syntaxhighlight>


===Functional solution 1===
===Functional solution 1===
<lang scala>fun fizzBuzz1() {
<syntaxhighlight lang="scala">fun fizzBuzz1() {
fun fizzBuzz(x: Int) = if (x % 15 == 0) "FizzBuzz" else x.toString()
fun fizzBuzz(x: Int) = if (x % 15 == 0) "FizzBuzz" else x.toString()
fun fizz(x: Any) = if (x is Int && x % 3 == 0) "Buzz" else x
fun fizz(x: Any) = if (x is Int && x % 3 == 0) "Buzz" else x
Line 5,459: Line 5,459:


(1..100).map { fizzBuzz(it) }.map { fizz(it) }.map { buzz(it) }.forEach { println(it) }
(1..100).map { fizzBuzz(it) }.map { fizz(it) }.map { buzz(it) }.forEach { println(it) }
}</lang>
}</syntaxhighlight>


===Functional solution 2===
===Functional solution 2===
<lang scala>fun fizzBuzz2() {
<syntaxhighlight lang="scala">fun fizzBuzz2() {
fun fizz(x: Pair<Int, StringBuilder>) = if(x.first % 3 == 0) x.apply { second.append("Fizz") } else x
fun fizz(x: Pair<Int, StringBuilder>) = if(x.first % 3 == 0) x.apply { second.append("Fizz") } else x
fun buzz(x: Pair<Int, StringBuilder>) = if(x.first % 5 == 0) x.apply { second.append("Buzz") } else x
fun buzz(x: Pair<Int, StringBuilder>) = if(x.first % 5 == 0) x.apply { second.append("Buzz") } else x
Line 5,472: Line 5,472:
.map { none(it) }
.map { none(it) }
.forEach { println(it) }
.forEach { println(it) }
}</lang>
}</syntaxhighlight>


===Short version with mapOf===
===Short version with mapOf===
<lang scala>
<syntaxhighlight lang="scala">
fun fizzBuzz() {
fun fizzBuzz() {
(1..100).forEach { println(mapOf(0 to it, it % 3 to "Fizz", it % 5 to "Buzz", it % 15 to "FizzBuzz")[0]) }
(1..100).forEach { println(mapOf(0 to it, it % 3 to "Fizz", it % 5 to "Buzz", it % 15 to "FizzBuzz")[0]) }
}
}
</syntaxhighlight>
</lang>


=={{header|KQL}}==
=={{header|KQL}}==
<lang kql>
<syntaxhighlight lang="kql">
range i from 1 to 100 step 1
range i from 1 to 100 step 1
| project Result =
| project Result =
Line 5,491: Line 5,491:
tostring(i)
tostring(i)
)
)
</syntaxhighlight>
</lang>


=={{header|KSI}}==
=={{header|KSI}}==
<lang ksi>
<syntaxhighlight lang="ksi">
`plain
`plain
[1 100] `for pos : n ~
[1 100] `for pos : n ~
Line 5,502: Line 5,502:
(out `or n) #write_ln #
(out `or n) #write_ln #
;
;
</syntaxhighlight>
</lang>


=={{header|LabVIEW}}==
=={{header|LabVIEW}}==
Line 5,509: Line 5,509:


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
<lang Scheme>
1. direct:
1. direct:


Line 5,543: Line 5,543:
-> same as above.
-> same as above.


</syntaxhighlight>
</lang>


=={{header|langur}}==
=={{header|langur}}==
<lang langur>for .i of 100 {
<syntaxhighlight lang="langur">for .i of 100 {
writeln given(0; .i rem 15: "FizzBuzz"; .i rem 5: "Buzz"; .i rem 3: "Fizz"; .i)
writeln given(0; .i rem 15: "FizzBuzz"; .i rem 5: "Buzz"; .i rem 3: "Fizz"; .i)
}</lang>
}</syntaxhighlight>


{{works with|langur|0.8.1}}
{{works with|langur|0.8.1}}
<lang langur>for .i of 100 {
<syntaxhighlight lang="langur">for .i of 100 {
writeln if(.i div 15: "FizzBuzz"; .i div 5: "Buzz"; .i div 3: "Fizz"; .i)
writeln if(.i div 15: "FizzBuzz"; .i div 5: "Buzz"; .i div 3: "Fizz"; .i)
}</lang>
}</syntaxhighlight>


=={{header|Lasso}}==
=={{header|Lasso}}==
<lang lasso>with i in generateSeries(1, 100)
<syntaxhighlight lang="lasso">with i in generateSeries(1, 100)
select ((#i % 3 == 0 ? 'Fizz' | '') + (#i % 5 == 0 ? 'Buzz' | '') || #i)</lang>
select ((#i % 3 == 0 ? 'Fizz' | '') + (#i % 5 == 0 ? 'Buzz' | '') || #i)</syntaxhighlight>


=={{header|LaTeX}}==
=={{header|LaTeX}}==
Line 5,563: Line 5,563:
{{libheader|intcalc}}
{{libheader|intcalc}}
This version uses the ifthen and intcalc packages. There sure are more native solutions including solutions in plain TeX, but for me this is a readable and comprehensible one.
This version uses the ifthen and intcalc packages. There sure are more native solutions including solutions in plain TeX, but for me this is a readable and comprehensible one.
<lang LaTeX>\documentclass{minimal}
<syntaxhighlight lang="latex">\documentclass{minimal}
\usepackage{ifthen}
\usepackage{ifthen}
\usepackage{intcalc}
\usepackage{intcalc}
Line 5,581: Line 5,581:
\begin{document}
\begin{document}
\fizzBuzz{101}
\fizzBuzz{101}
\end{document}</lang>
\end{document}</syntaxhighlight>


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
Line 5,587: Line 5,587:


=={{header|LIL}}==
=={{header|LIL}}==
<lang tcl># fizzbuzz in LIL
<syntaxhighlight lang="tcl"># fizzbuzz in LIL
for {set i 1} {$i <= 100} {inc i} {
for {set i 1} {$i <= 100} {inc i} {
set show ""
set show ""
Line 5,594: Line 5,594:
if {[expr [length $show] == 0]} {set show $i}
if {[expr [length $show] == 0]} {set show $i}
print $show
print $show
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 5,616: Line 5,616:


=={{header|LiveCode}}==
=={{header|LiveCode}}==
<lang LiveCode>repeat with i = 1 to 100
<syntaxhighlight lang="livecode">repeat with i = 1 to 100
switch
switch
case i mod 15 = 0
case i mod 15 = 0
Line 5,631: Line 5,631:
end switch
end switch
end repeat
end repeat
put fizzbuzz</lang>
put fizzbuzz</syntaxhighlight>


=={{header|LiveScript}}==
=={{header|LiveScript}}==
See: http://livescript.net/blog/fizzbuzzbazz.html
See: http://livescript.net/blog/fizzbuzzbazz.html
<lang LiveScript>[1 to 100] map -> [k + \zz for k, v of {Fi: 3, Bu: 5} | it % v < 1] * '' || it</lang>
<syntaxhighlight lang="livescript">[1 to 100] map -> [k + \zz for k, v of {Fi: 3, Bu: 5} | it % v < 1] * '' || it</syntaxhighlight>


=={{header|LLVM}}==
=={{header|LLVM}}==
<lang llvm>; ModuleID = 'fizzbuzz.c'
<syntaxhighlight lang="llvm">; ModuleID = 'fizzbuzz.c'
; source_filename = "fizzbuzz.c"
; source_filename = "fizzbuzz.c"
; target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
; target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
Line 5,738: Line 5,738:
!0 = !{i32 1, !"wchar_size", i32 2}
!0 = !{i32 1, !"wchar_size", i32 2}
!1 = !{i32 7, !"PIC Level", i32 2}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{!"clang version 6.0.1 (tags/RELEASE_601/final)"}</lang>
!2 = !{!"clang version 6.0.1 (tags/RELEASE_601/final)"}</syntaxhighlight>


=={{header|Lobster}}==
=={{header|Lobster}}==
<lang Lobster>include "std.lobster"
<syntaxhighlight lang="lobster">include "std.lobster"


forbias(100, 1) i:
forbias(100, 1) i:
fb := (i % 3 == 0 and "fizz" or "") +
fb := (i % 3 == 0 and "fizz" or "") +
(i % 5 == 0 and "buzz" or "")
(i % 5 == 0 and "buzz" or "")
print fb.length and fb or "" + i</lang>
print fb.length and fb or "" + i</syntaxhighlight>


=={{header|Logo}}==
=={{header|Logo}}==
<lang logo>to fizzbuzz :n
<syntaxhighlight lang="logo">to fizzbuzz :n
output cond [ [[equal? 0 modulo :n 15] "FizzBuzz]
output cond [ [[equal? 0 modulo :n 15] "FizzBuzz]
[[equal? 0 modulo :n 5] "Buzz]
[[equal? 0 modulo :n 5] "Buzz]
Line 5,756: Line 5,756:
end
end


repeat 100 [print fizzbuzz #]</lang>
repeat 100 [print fizzbuzz #]</syntaxhighlight>
"cond" was undefined in Joshua Bell's online interpreter. So here is a version that works there. It also works in UCB logo by using # instead of "repcount". This version also factors away modulo 15:
"cond" was undefined in Joshua Bell's online interpreter. So here is a version that works there. It also works in UCB logo by using # instead of "repcount". This version also factors away modulo 15:
<lang logo>to fizzbuzz :n
<syntaxhighlight lang="logo">to fizzbuzz :n
make "c "
make "c "
if equal? 0 modulo :n 5 [make "c "Buzz]
if equal? 0 modulo :n 5 [make "c "Buzz]
Line 5,765: Line 5,765:
end
end


repeat 100 [print fizzbuzz repcount]</lang>
repeat 100 [print fizzbuzz repcount]</syntaxhighlight>
Lhogho can use the above code, except that 'modulo' must be replaced with 'remainder'.
Lhogho can use the above code, except that 'modulo' must be replaced with 'remainder'.


Line 5,772: Line 5,772:


=={{header|LSE}}==
=={{header|LSE}}==
<lang LSE>1* FIZZBUZZ en L.S.E.
<syntaxhighlight lang="lse">1* FIZZBUZZ en L.S.E.
10 CHAINE FB
10 CHAINE FB
20 FAIRE 45 POUR I_1 JUSQUA 100
20 FAIRE 45 POUR I_1 JUSQUA 100
Line 5,780: Line 5,780:
50 TERMINER
50 TERMINER
100 PROCEDURE &MOD(A,B) LOCAL A,B
100 PROCEDURE &MOD(A,B) LOCAL A,B
110 RESULTAT A-B*ENT(A/B)</lang>
110 RESULTAT A-B*ENT(A/B)</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
===If/else Ladder===
===If/else Ladder===
<lang Lua>for i = 1, 100 do
<syntaxhighlight lang="lua">for i = 1, 100 do
if i % 15 == 0 then
if i % 15 == 0 then
print("FizzBuzz")
print("FizzBuzz")
Line 5,794: Line 5,794:
print(i)
print(i)
end
end
end</lang>
end</syntaxhighlight>
===Concatenation===
===Concatenation===
<lang Lua>for i = 1, 100 do
<syntaxhighlight lang="lua">for i = 1, 100 do
output = ""
output = ""
if i % 3 == 0 then
if i % 3 == 0 then
Line 5,808: Line 5,808:
end
end
print(output)
print(output)
end</lang>
end</syntaxhighlight>


===Quasi bit field===
===Quasi bit field===
<lang Lua>word = {"Fizz", "Buzz", "FizzBuzz"}
<syntaxhighlight lang="lua">word = {"Fizz", "Buzz", "FizzBuzz"}


for i = 1, 100 do
for i = 1, 100 do
print(word[(i % 3 == 0 and 1 or 0) + (i % 5 == 0 and 2 or 0)] or i)
print(word[(i % 3 == 0 and 1 or 0) + (i % 5 == 0 and 2 or 0)] or i)
end</lang>
end</syntaxhighlight>


===Lookup table===
===Lookup table===
<lang Lua>local t = {
<syntaxhighlight lang="lua">local t = {
[0] = "FizzBuzz",
[0] = "FizzBuzz",
[3] = "Fizz",
[3] = "Fizz",
Line 5,830: Line 5,830:
for i = 1, 100 do
for i = 1, 100 do
print(t[i%15] or i)
print(t[i%15] or i)
end</lang>
end</syntaxhighlight>


=== Fast Version without Modulo ===
=== Fast Version without Modulo ===
<lang lua>
<syntaxhighlight lang="lua">
#!/usr/bin/env luajit
#!/usr/bin/env luajit
local to=arg[1] or tonumber(arg[1]) or 100
local to=arg[1] or tonumber(arg[1]) or 100
Line 5,854: Line 5,854:
io.write(", ")
io.write(", ")
end
end
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 5,863: Line 5,863:


=={{header|Luck}}==
=={{header|Luck}}==
<lang Luck>for i in range(1,101) do (
<syntaxhighlight lang="luck">for i in range(1,101) do (
if i%15 == 0 then print("FizzBuzz")
if i%15 == 0 then print("FizzBuzz")
else if i%3 == 0 then print("Fizz")
else if i%3 == 0 then print("Fizz")
else if i%5 == 0 then print("Buzz")
else if i%5 == 0 then print("Buzz")
else print(i)
else print(i)
)</lang>
)</syntaxhighlight>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
\\ one line, hard to read
\\ one line, hard to read
For i=1 to 100 {If i mod 3=0 Then {if i mod 5=0 Then Print "FizzBuzz", Else Print "Fizz",} Else {if i mod 5=0 Then Print "Buzz", else print i, } } : Print
For i=1 to 100 {If i mod 3=0 Then {if i mod 5=0 Then Print "FizzBuzz", Else Print "Fizz",} Else {if i mod 5=0 Then Print "Buzz", else print i, } } : Print
Line 5,890: Line 5,890:
If a$<>"" Then Print a$, else Print i,
If a$<>"" Then Print a$, else Print i,
End Sub
End Sub
</syntaxhighlight>
</lang>


=={{header|M4}}==
=={{header|M4}}==
<lang M4>define(`for',
<syntaxhighlight lang="m4">define(`for',
`ifelse($#,0,``$0'',
`ifelse($#,0,``$0'',
`ifelse(eval($2<=$3),1,
`ifelse(eval($2<=$3),1,
Line 5,902: Line 5,902:
`ifelse(eval(x%3==0),1,Fizz,
`ifelse(eval(x%3==0),1,Fizz,
`ifelse(eval(x%5==0),1,Buzz,x)')')
`ifelse(eval(x%5==0),1,Buzz,x)')')
')</lang>
')</syntaxhighlight>


=={{header|make}}==
=={{header|make}}==
{{works with|BSD make}}
{{works with|BSD make}}
{{libheader|jot}}
{{libheader|jot}}
<lang make>MOD3 = 0
<syntaxhighlight lang="make">MOD3 = 0
MOD5 = 0
MOD5 = 0
ALL != jot 100
ALL != jot 100
Line 5,934: Line 5,934:
. endif
. endif


.endfor</lang>
.endfor</syntaxhighlight>


=={{header|Maple}}==
=={{header|Maple}}==
One line:
One line:
<lang Maple>seq(print(`if`(modp(n,3)=0,`if`(modp(n,15)=0,"FizzBuzz","Fizz"),`if`(modp(n,5)=0,"Buzz",n))),n=1..100):</lang>
<syntaxhighlight lang="maple">seq(print(`if`(modp(n,3)=0,`if`(modp(n,15)=0,"FizzBuzz","Fizz"),`if`(modp(n,5)=0,"Buzz",n))),n=1..100):</syntaxhighlight>
With a fizzbuzz function defined:
With a fizzbuzz function defined:
<lang Maple>fizzbuzz1 := n->`if`(modp(n,3)=0,`if`(modp(n,15)=0,"FizzBuzz","Fizz"),`if`(modp(n,5)=0,"Buzz",n)):
<syntaxhighlight lang="maple">fizzbuzz1 := n->`if`(modp(n,3)=0,`if`(modp(n,15)=0,"FizzBuzz","Fizz"),`if`(modp(n,5)=0,"Buzz",n)):
for i to 100 do fizzbuzz1(i); od;</lang>
for i to 100 do fizzbuzz1(i); od;</syntaxhighlight>
Using piecewise:
Using piecewise:
<lang Maple>fizzbuzz2 := n->piecewise(modp(n,15)=0,"FizzBuzz",modp(n,3)=0,"Fizz",modp(n,5)=0,"Buzz",n):
<syntaxhighlight lang="maple">fizzbuzz2 := n->piecewise(modp(n,15)=0,"FizzBuzz",modp(n,3)=0,"Fizz",modp(n,5)=0,"Buzz",n):
for i to 100 do fizzbuzz2(i); od;</lang>
for i to 100 do fizzbuzz2(i); od;</syntaxhighlight>
Using conventional if/then branches:
Using conventional if/then branches:
<lang Maple>fizzbuzz3 := proc(n) local r;
<syntaxhighlight lang="maple">fizzbuzz3 := proc(n) local r;
r:=map2(modp,n,[3,5]);
r:=map2(modp,n,[3,5]);
if r=[0,0] then "FizzBuzz"
if r=[0,0] then "FizzBuzz"
Line 5,953: Line 5,953:
else n fi;
else n fi;
end proc:
end proc:
for i to 100 do fizzbuzz3(i); od;</lang>
for i to 100 do fizzbuzz3(i); od;</syntaxhighlight>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>Do[Print[Which[Mod[i, 15] == 0, "FizzBuzz", Mod[i, 5] == 0, "Buzz", Mod[i, 3] == 0, "Fizz", True, i]], {i, 100}]</lang>
<syntaxhighlight lang="mathematica">Do[Print[Which[Mod[i, 15] == 0, "FizzBuzz", Mod[i, 5] == 0, "Buzz", Mod[i, 3] == 0, "Fizz", True, i]], {i, 100}]</syntaxhighlight>
Using rules,
Using rules,
<lang Mathematica>fizz[i_] := Mod[i, 3] == 0
<syntaxhighlight lang="mathematica">fizz[i_] := Mod[i, 3] == 0
buzz[i_] := Mod[i, 5] == 0
buzz[i_] := Mod[i, 5] == 0
Range[100] /. {i_ /; fizz[i]&&buzz[i] :> "FizzBuzz", \
Range[100] /. {i_ /; fizz[i]&&buzz[i] :> "FizzBuzz", \
i_?fizz :> "Fizz", i_?buzz :> "Buzz"}</lang>
i_?fizz :> "Fizz", i_?buzz :> "Buzz"}</syntaxhighlight>
Using rules, but different approach:
Using rules, but different approach:
<lang Mathematica>SetAttributes[f,Listable]
<syntaxhighlight lang="mathematica">SetAttributes[f,Listable]
f[n_ /; Mod[n, 15] == 0] := "FizzBuzz";
f[n_ /; Mod[n, 15] == 0] := "FizzBuzz";
f[n_ /; Mod[n, 3] == 0] := "Fizz";
f[n_ /; Mod[n, 3] == 0] := "Fizz";
Line 5,969: Line 5,969:
f[n_] := n;
f[n_] := n;


f[Range[100]]</lang>
f[Range[100]]</syntaxhighlight>
An extendible version using Table
An extendible version using Table
<lang Mathematica>Table[If[# === "", i, #]&@StringJoin[
<syntaxhighlight lang="mathematica">Table[If[# === "", i, #]&@StringJoin[
Table[If[Divisible[i, First@nw], Last@nw, ""],
Table[If[Divisible[i, First@nw], Last@nw, ""],
{nw, {{3, "Fizz"}, {5, "Buzz"}}}]],
{nw, {{3, "Fizz"}, {5, "Buzz"}}}]],
{i, 1, 100}]</lang>
{i, 1, 100}]</syntaxhighlight>
Another one-liner using Map (the /@ operator shorthand of it) and a pure function with a very readable Which
Another one-liner using Map (the /@ operator shorthand of it) and a pure function with a very readable Which
<lang Mathematica> Which[ Mod[#,15] == 0, "FizzBuzz", Mod[#, 3] == 0, "Fizz", Mod[#,5]==0, "Buzz", True, #]& /@ Range[1,100] </lang>
<syntaxhighlight lang="mathematica"> Which[ Mod[#,15] == 0, "FizzBuzz", Mod[#, 3] == 0, "Fizz", Mod[#,5]==0, "Buzz", True, #]& /@ Range[1,100] </syntaxhighlight>


=={{header|MATLAB}}==
=={{header|MATLAB}}==
There are more sophisticated solutions to this task, but in the spirit of "lowest level of comprehension required to illustrate adequacy" this is what one might expect from a novice programmer (with a little variation in how the strings are stored and displayed).
There are more sophisticated solutions to this task, but in the spirit of "lowest level of comprehension required to illustrate adequacy" this is what one might expect from a novice programmer (with a little variation in how the strings are stored and displayed).
<lang MATLAB>function fizzBuzz()
<syntaxhighlight lang="matlab">function fizzBuzz()
for i = (1:100)
for i = (1:100)
if mod(i,15) == 0
if mod(i,15) == 0
Line 5,993: Line 5,993:
end
end
fprintf('\n');
fprintf('\n');
end</lang>
end</syntaxhighlight>
Here's a more extendible version that uses disp() to print the output:
Here's a more extendible version that uses disp() to print the output:
<lang MATLAB>function out = fizzbuzzS()
<syntaxhighlight lang="matlab">function out = fizzbuzzS()
nums = [3, 5];
nums = [3, 5];
words = {'fizz', 'buzz'};
words = {'fizz', 'buzz'};
Line 6,011: Line 6,011:
end
end
end
end
end</lang>
end</syntaxhighlight>


=={{header|Maxima}}==
=={{header|Maxima}}==
<lang maxima>for n:1 thru 100 do
<syntaxhighlight lang="maxima">for n:1 thru 100 do
if mod(n, 15) = 0 then (sprint("FizzBuzz"), newline())
if mod(n, 15) = 0 then (sprint("FizzBuzz"), newline())
elseif mod(n, 3) = 0 then (sprint("Fizz"), newline())
elseif mod(n, 3) = 0 then (sprint("Fizz"), newline())
elseif mod(n,5) = 0 then (sprint("Buzz"), newline())
elseif mod(n,5) = 0 then (sprint("Buzz"), newline())
else (sprint(n), newline());</lang>
else (sprint(n), newline());</syntaxhighlight>


=={{header|MAXScript}}==
=={{header|MAXScript}}==
<lang maxscript>for i in 1 to 100 do
<syntaxhighlight lang="maxscript">for i in 1 to 100 do
(
(
case of
case of
Line 6,030: Line 6,030:
default: (print i)
default: (print i)
)
)
)</lang>
)</syntaxhighlight>


=={{header|MEL}}==
=={{header|MEL}}==
<lang mel>for($i=1; $i<=100; $i++)
<syntaxhighlight lang="mel">for($i=1; $i<=100; $i++)
{
{
if($i % 15 == 0)
if($i % 15 == 0)
Line 6,043: Line 6,043:
else
else
print ($i + "\n");
print ($i + "\n");
}</lang>
}</syntaxhighlight>


=={{header|Mercury}}==
=={{header|Mercury}}==
<lang mercury>:- module fizzbuzz.
<syntaxhighlight lang="mercury">:- module fizzbuzz.
:- interface.
:- interface.
:- import_module io.
:- import_module io.
Line 6,076: Line 6,076:
else
else
true
true
).</lang>
).</syntaxhighlight>


=={{header|Metafont}}==
=={{header|Metafont}}==
<lang metafont>for i := 1 upto 100:
<syntaxhighlight lang="metafont">for i := 1 upto 100:
message if i mod 15 = 0: "FizzBuzz" &
message if i mod 15 = 0: "FizzBuzz" &
elseif i mod 3 = 0: "Fizz" &
elseif i mod 3 = 0: "Fizz" &
Line 6,085: Line 6,085:
else: decimal i & fi "";
else: decimal i & fi "";
endfor
endfor
end</lang>
end</syntaxhighlight>


=={{header|Microsoft Small Basic}}==
=={{header|Microsoft Small Basic}}==
{{trans|GW-BASIC}}
{{trans|GW-BASIC}}
<lang microsoftsmallbasic>
<syntaxhighlight lang="microsoftsmallbasic">
For n = 1 To 100
For n = 1 To 100
op = ""
op = ""
Line 6,104: Line 6,104:
EndIf
EndIf
EndFor
EndFor
</syntaxhighlight>
</lang>


=={{header|min}}==
=={{header|min}}==
{{works with|min|0.19.3}}
{{works with|min|0.19.3}}
<lang min>0 (
<syntaxhighlight lang="min">0 (
succ false :hit
succ false :hit
(3 mod 0 ==) ("Fizz" print! true @hit) when
(3 mod 0 ==) ("Fizz" print! true @hit) when
(5 mod 0 ==) ("Buzz" print! true @hit) when
(5 mod 0 ==) ("Buzz" print! true @hit) when
(hit) (print) unless newline
(hit) (print) unless newline
) 100 times</lang>
) 100 times</syntaxhighlight>


=={{header|MiniScript}}==
=={{header|MiniScript}}==
<lang MiniScript>for i in range(1,100)
<syntaxhighlight lang="miniscript">for i in range(1,100)
if i % 15 == 0 then
if i % 15 == 0 then
print "FizzBuzz"
print "FizzBuzz"
Line 6,126: Line 6,126:
print i
print i
end if
end if
end for</lang>
end for</syntaxhighlight>


=={{header|MIPS Assembly}}==
=={{header|MIPS Assembly}}==
<lang mips>
<syntaxhighlight lang="mips">
#################################
#################################
# Fizz Buzz #
# Fizz Buzz #
Line 6,204: Line 6,204:
li $v0,10
li $v0,10
syscall
syscall
</syntaxhighlight>
</lang>


=={{header|Mirah}}==
=={{header|Mirah}}==
<lang mirah>1.upto(100) do |n|
<syntaxhighlight lang="mirah">1.upto(100) do |n|
print "Fizz" if a = ((n % 3) == 0)
print "Fizz" if a = ((n % 3) == 0)
print "Buzz" if b = ((n % 5) == 0)
print "Buzz" if b = ((n % 5) == 0)
print n unless (a || b)
print n unless (a || b)
print "\n"
print "\n"
end</lang>
end</syntaxhighlight>


A little more straight forward:
A little more straight forward:
<lang mirah>1.upto(100) do |n|
<syntaxhighlight lang="mirah">1.upto(100) do |n|
if (n % 15) == 0
if (n % 15) == 0
puts "FizzBuzz"
puts "FizzBuzz"
Line 6,225: Line 6,225:
puts n
puts n
end
end
end</lang>
end</syntaxhighlight>


=={{header|ML}}==
=={{header|ML}}==
==={{header|Standard ML}}===
==={{header|Standard ML}}===
First using two helper functions, one for deciding what to output and another for performing recursion with an auxiliary argument j.
First using two helper functions, one for deciding what to output and another for performing recursion with an auxiliary argument j.
<lang sml>local
<syntaxhighlight lang="sml">local
fun fbstr i =
fun fbstr i =
case (i mod 3 = 0, i mod 5 = 0) of
case (i mod 3 = 0, i mod 5 = 0) of
Line 6,243: Line 6,243:
fun fizzbuzz n = fizzbuzz' (n, 1)
fun fizzbuzz n = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
val _ = fizzbuzz 100
end</lang>
end</syntaxhighlight>


Second using the standard-library combinator List.tabulate and a helper function, fb, that calculates and prints the output.
Second using the standard-library combinator List.tabulate and a helper function, fb, that calculates and prints the output.
<lang sml>local
<syntaxhighlight lang="sml">local
fun fb i = let val fizz = i mod 3 = 0 andalso (print "Fizz"; true)
fun fb i = let val fizz = i mod 3 = 0 andalso (print "Fizz"; true)
val buzz = i mod 5 = 0 andalso (print "Buzz"; true)
val buzz = i mod 5 = 0 andalso (print "Buzz"; true)
Line 6,253: Line 6,253:
fun fizzbuzz n = (List.tabulate (n, fn i => (fb (i+1); print "\n")); ())
fun fizzbuzz n = (List.tabulate (n, fn i => (fb (i+1); print "\n")); ())
val _ = fizzbuzz 100
val _ = fizzbuzz 100
end</lang>
end</syntaxhighlight>


==={{header|mLite}}===
==={{header|mLite}}===
<lang ocaml>local
<syntaxhighlight lang="ocaml">local
fun fizzbuzz'
fun fizzbuzz'
(x mod 15 = 0) = "FizzBuzz"
(x mod 15 = 0) = "FizzBuzz"
Line 6,271: Line 6,271:


println ` fizzbuzz ` iota 100;
println ` fizzbuzz ` iota 100;
</syntaxhighlight>
</lang>


=={{header|MMIX}}==
=={{header|MMIX}}==
<lang mmix>t IS $255
<syntaxhighlight lang="mmix">t IS $255
Ja IS $127
Ja IS $127


Line 6,336: Line 6,336:
JMP 1B % repeat for next i
JMP 1B % repeat for next i
4H XOR t,t,t
4H XOR t,t,t
TRAP 0,Halt,0 % exit(0)</lang>
TRAP 0,Halt,0 % exit(0)</syntaxhighlight>


=={{header|Modula-2}}==
=={{header|Modula-2}}==
<lang modula2>MODULE Fizzbuzz;
<syntaxhighlight lang="modula2">MODULE Fizzbuzz;
FROM FormatString IMPORT FormatString;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
Line 6,384: Line 6,384:


ReadChar
ReadChar
END Fizzbuzz.</lang>
END Fizzbuzz.</syntaxhighlight>


=={{header|Modula-3}}==
=={{header|Modula-3}}==
<lang modula3>MODULE Fizzbuzz EXPORTS Main;
<syntaxhighlight lang="modula3">MODULE Fizzbuzz EXPORTS Main;


IMPORT IO;
IMPORT IO;
Line 6,404: Line 6,404:
END;
END;
END;
END;
END Fizzbuzz.</lang>
END Fizzbuzz.</syntaxhighlight>


=={{header|Monte}}==
=={{header|Monte}}==


<lang Monte>def fizzBuzz(top):
<syntaxhighlight lang="monte">def fizzBuzz(top):
var t := 1
var t := 1
while (t < top):
while (t < top):
Line 6,421: Line 6,421:


fizzBuzz(100)
fizzBuzz(100)
</syntaxhighlight>
</lang>


=={{header|MontiLang}}==
=={{header|MontiLang}}==


<lang MontiLang>&DEFINE LOOP 100&
<syntaxhighlight lang="montilang">&DEFINE LOOP 100&
1 VAR i .
1 VAR i .


Line 6,447: Line 6,447:
ENDIF
ENDIF
i 1 + VAR i .
i 1 + VAR i .
ENDFOR</lang>
ENDFOR</syntaxhighlight>


=={{header|MoonScript}}==
=={{header|MoonScript}}==


<lang moonscript>for i = 1,100
<syntaxhighlight lang="moonscript">for i = 1,100
print ((a) -> a == "" and i or a) table.concat {
print ((a) -> a == "" and i or a) table.concat {
i % 3 == 0 and "Fizz" or ""
i % 3 == 0 and "Fizz" or ""
i % 5 == 0 and "Buzz" or ""}</lang>
i % 5 == 0 and "Buzz" or ""}</syntaxhighlight>


=={{header|MUMPS}}==
=={{header|MUMPS}}==
<lang MUMPS>FIZZBUZZ
<syntaxhighlight lang="mumps">FIZZBUZZ
NEW I
NEW I
FOR I=1:1:100 WRITE !,$SELECT(('(I#3)&'(I#5)):"FizzBuzz",'(I#5):"Buzz",'(I#3):"Fizz",1:I)
FOR I=1:1:100 WRITE !,$SELECT(('(I#3)&'(I#5)):"FizzBuzz",'(I#5):"Buzz",'(I#3):"Fizz",1:I)
KILL I
KILL I
QUIT</lang>
QUIT</syntaxhighlight>


<lang MUMPS>fizzbuzz
<syntaxhighlight lang="mumps">fizzbuzz
for i=1:1:100 do write !
for i=1:1:100 do write !
. write:(i#3)&(i#5) i write:'(i#3) "Fizz" write:'(i#5) "Buzz"</lang>
. write:(i#3)&(i#5) i write:'(i#3) "Fizz" write:'(i#5) "Buzz"</syntaxhighlight>


=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
<lang Nanoquery>for i in range(1, 100)
<syntaxhighlight lang="nanoquery">for i in range(1, 100)
if ((i % 3) = 0) and ((i % 5) = 0)
if ((i % 3) = 0) and ((i % 5) = 0)
println "FizzBuzz"
println "FizzBuzz"
Line 6,478: Line 6,478:
println i
println i
end
end
end</lang>
end</syntaxhighlight>


=={{header|NATURAL}}==
=={{header|NATURAL}}==
<syntaxhighlight lang="natural">
<lang NATURAL>
DEFINE DATA
DEFINE DATA
LOCAL
LOCAL
Line 6,515: Line 6,515:
*
*
END
END
</syntaxhighlight>
</lang>


=={{header|Neko}}==
=={{header|Neko}}==
<lang Neko>var i = 1
<syntaxhighlight lang="neko">var i = 1


while(i < 100) {
while(i < 100) {
Line 6,532: Line 6,532:


i ++= 1
i ++= 1
}</lang>
}</syntaxhighlight>


=={{header|Nemerle}}==
=={{header|Nemerle}}==
The naive approach:
The naive approach:
<lang Nemerle>using System;
<syntaxhighlight lang="nemerle">using System;
using System.Console;
using System.Console;


Line 6,554: Line 6,554:
WriteLine($"$(FizzBuzz(i))")
WriteLine($"$(FizzBuzz(i))")
}
}
}</lang>
}</syntaxhighlight>
A much slicker approach is [http://www.dreamincode.net/forums/blog/217/entry-3539-fizzbuzz-in-nemerle/ posted here]
A much slicker approach is [http://www.dreamincode.net/forums/blog/217/entry-3539-fizzbuzz-in-nemerle/ posted here]


=={{header|NetRexx}}==
=={{header|NetRexx}}==
<lang netrexx>loop j=1 for 100
<syntaxhighlight lang="netrexx">loop j=1 for 100
select
select
when j//15==0 then say 'FizzBuzz'
when j//15==0 then say 'FizzBuzz'
Line 6,565: Line 6,565:
otherwise say j.right(4)
otherwise say j.right(4)
end
end
end</lang>
end</syntaxhighlight>


=={{header|Never}}==
=={{header|Never}}==
<lang fsharp>func fizz_buzz() -> int
<syntaxhighlight lang="fsharp">func fizz_buzz() -> int
{
{
var i = 1;
var i = 1;
Line 6,600: Line 6,600:


0
0
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 6,635: Line 6,635:


=={{header|NewLISP}}==
=={{header|NewLISP}}==
<lang NewLISP>(dotimes (i 100)
<syntaxhighlight lang="newlisp">(dotimes (i 100)
(println
(println
(cond
(cond
Line 6,641: Line 6,641:
((= 0 (% i 3)) "Fizz")
((= 0 (% i 3)) "Fizz")
((= 0 (% i 5)) "Buzz")
((= 0 (% i 5)) "Buzz")
('t i))))</lang>
('t i))))</syntaxhighlight>


=={{header|NewtonScript}}==
=={{header|NewtonScript}}==
<lang newton>for i := 1 to 100 do
<syntaxhighlight lang="newton">for i := 1 to 100 do
begin
begin
if i mod 15 = 0 then
if i mod 15 = 0 then
Line 6,655: Line 6,655:
print(i);
print(i);
print("\n")
print("\n")
end</lang>
end</syntaxhighlight>


=={{header|Nickle}}==
=={{header|Nickle}}==
<lang nickle>/* Fizzbuzz in nickle */
<syntaxhighlight lang="nickle">/* Fizzbuzz in nickle */


void function fizzbuzz(size) {
void function fizzbuzz(size) {
Line 6,669: Line 6,669:
}
}


fizzbuzz(1000);</lang>
fizzbuzz(1000);</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Python}}
{{trans|Python}}
<lang nim>for i in 1..100:
<syntaxhighlight lang="nim">for i in 1..100:
if i mod 15 == 0:
if i mod 15 == 0:
echo("FizzBuzz")
echo("FizzBuzz")
Line 6,681: Line 6,681:
echo("Buzz")
echo("Buzz")
else:
else:
echo(i)</lang>
echo(i)</syntaxhighlight>


===Without Modulus===
===Without Modulus===
<lang nim>var messages = @["", "Fizz", "Buzz", "FizzBuzz"]
<syntaxhighlight lang="nim">var messages = @["", "Fizz", "Buzz", "FizzBuzz"]
var acc = 810092048
var acc = 810092048
for i in 1..100:
for i in 1..100:
var c = acc and 3
var c = acc and 3
echo(if c == 0: $i else: messages[c])
echo(if c == 0: $i else: messages[c])
acc = acc shr 2 or c shl 28</lang>
acc = acc shr 2 or c shl 28</syntaxhighlight>


===Using macro===
===Using macro===
Computes everything at compile time.
Computes everything at compile time.
<lang nim>import macros
<syntaxhighlight lang="nim">import macros
macro FizzBuzz(N): untyped =
macro FizzBuzz(N): untyped =
var source = ""
var source = ""
Line 6,709: Line 6,709:
result = parseStmt(source)
result = parseStmt(source)


FizzBuzz(100)</lang>
FizzBuzz(100)</syntaxhighlight>


=={{header|Nix}}==
=={{header|Nix}}==
<lang nix>with (import <nixpkgs> { }).lib;
<syntaxhighlight lang="nix">with (import <nixpkgs> { }).lib;
with builtins;
with builtins;
let
let
Line 6,728: Line 6,728:
fizzbuzz { x = x + 1; } else "");
fizzbuzz { x = x + 1; } else "");
in
in
fizzbuzz { }</lang>
fizzbuzz { }</syntaxhighlight>


=={{header|Oberon-2}}==
=={{header|Oberon-2}}==
<lang oberon2>MODULE FizzBuzz;
<syntaxhighlight lang="oberon2">MODULE FizzBuzz;


IMPORT Out;
IMPORT Out;
Line 6,750: Line 6,750:
Out.Ln
Out.Ln
END
END
END FizzBuzz.</lang>
END FizzBuzz.</syntaxhighlight>


=={{header|Objeck}}==
=={{header|Objeck}}==
<lang objeck>bundle Default {
<syntaxhighlight lang="objeck">bundle Default {
class Fizz {
class Fizz {
function : Main(args : String[]) ~ Nil {
function : Main(args : String[]) ~ Nil {
Line 6,772: Line 6,772:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|Objective-C}}==
=={{header|Objective-C}}==
<lang c>// FizzBuzz in Objective-C
<syntaxhighlight lang="c">// FizzBuzz in Objective-C
#import <Foundation/Foundation.h>
#import <Foundation/Foundation.h>


Line 6,790: Line 6,790:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|OCaml}}==
=={{header|OCaml}}==
Line 6,796: Line 6,796:
Idiomatic OCaml to solve the stated problem:
Idiomatic OCaml to solve the stated problem:


<lang ocaml>let fizzbuzz i =
<syntaxhighlight lang="ocaml">let fizzbuzz i =
match i mod 3, i mod 5 with
match i mod 3, i mod 5 with
0, 0 -> "FizzBuzz"
0, 0 -> "FizzBuzz"
Line 6,804: Line 6,804:
let _ =
let _ =
for i = 1 to 100 do print_endline (fizzbuzz i) done</lang>
for i = 1 to 100 do print_endline (fizzbuzz i) done</syntaxhighlight>


With a view toward extensibility, there are many approaches: monadic, list of rules, ... here we'll use a piped sequence of rules to define a new "fizzbuzz" function:
With a view toward extensibility, there are many approaches: monadic, list of rules, ... here we'll use a piped sequence of rules to define a new "fizzbuzz" function:


<lang ocaml>(* Useful rule declaration: "cond => f", 'cond'itionally applies 'f' to 'a'ccumulated value *)
<syntaxhighlight lang="ocaml">(* Useful rule declaration: "cond => f", 'cond'itionally applies 'f' to 'a'ccumulated value *)
let (=>) cond f a = if cond then f a else a
let (=>) cond f a = if cond then f a else a
let append s a = a^s
let append s a = a^s
Line 6,816: Line 6,816:
|> (i mod 5 = 0 => append "Buzz")
|> (i mod 5 = 0 => append "Buzz")
|> (function "" -> string_of_int i
|> (function "" -> string_of_int i
| s -> s)</lang>
| s -> s)</syntaxhighlight>


=={{header|Octave}}==
=={{header|Octave}}==
<lang octave>for i = 1:100
<syntaxhighlight lang="octave">for i = 1:100
if ( mod(i,15) == 0 )
if ( mod(i,15) == 0 )
disp("FizzBuzz");
disp("FizzBuzz");
Line 6,829: Line 6,829:
disp(i)
disp(i)
endif
endif
endfor</lang>
endfor</syntaxhighlight>


=={{header|Oforth}}==
=={{header|Oforth}}==


<lang Oforth>: fizzbuzz
<syntaxhighlight lang="oforth">: fizzbuzz
| i |
| i |
100 loop: i [
100 loop: i [
Line 6,840: Line 6,840:
i 5 mod ifZero: [ "Buzz" + ]
i 5 mod ifZero: [ "Buzz" + ]
dup ifNull: [ drop i ] .
dup ifNull: [ drop i ] .
] ; </lang>
] ; </syntaxhighlight>


=={{header|Ol}}==
=={{header|Ol}}==
<lang scheme>
<syntaxhighlight lang="scheme">
(for-each (lambda (x)
(for-each (lambda (x)
(print (cond
(print (cond
Line 6,855: Line 6,855:
x))))
x))))
(iota 100))
(iota 100))
</syntaxhighlight>
</lang>
=={{header|OOC}}==
=={{header|OOC}}==
<lang ooc>fizz: func (n: Int) -> Bool {
<syntaxhighlight lang="ooc">fizz: func (n: Int) -> Bool {
if(n % 3 == 0) {
if(n % 3 == 0) {
printf("Fizz")
printf("Fizz")
Line 6,880: Line 6,880:
println()
println()
}
}
}</lang>
}</syntaxhighlight>


=={{header|Order}}==
=={{header|Order}}==
<lang c>#include <order/interpreter.h>
<syntaxhighlight lang="c">#include <order/interpreter.h>


// Get FB for one number
// Get FB for one number
Line 6,901: Line 6,901:
ORDER_PP( // foreach instead of map, to print but return nothing
ORDER_PP( // foreach instead of map, to print but return nothing
8seq_for_each(8compose(8print_el, 8fizzbuzz), 8seq_iota(1, 100))
8seq_for_each(8compose(8print_el, 8fizzbuzz), 8seq_iota(1, 100))
)</lang>
)</syntaxhighlight>


=={{header|Oz}}==
=={{header|Oz}}==
<lang oz>declare
<syntaxhighlight lang="oz">declare
fun {FizzBuzz X}
fun {FizzBuzz X}
if X mod 15 == 0 then 'FizzBuzz'
if X mod 15 == 0 then 'FizzBuzz'
Line 6,915: Line 6,915:
for I in 1..100 do
for I in 1..100 do
{Show {FizzBuzz I}}
{Show {FizzBuzz I}}
end</lang>
end</syntaxhighlight>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<lang parigp>{for(n=1,100,
<syntaxhighlight lang="parigp">{for(n=1,100,
print(if(n%3,
print(if(n%3,
if(n%5,
if(n%5,
Line 6,932: Line 6,932:
)
)
))
))
)}</lang>
)}</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
<lang pascal>program fizzbuzz(output);
<syntaxhighlight lang="pascal">program fizzbuzz(output);
var
var
i: integer;
i: integer;
Line 6,948: Line 6,948:
else
else
writeln(i)
writeln(i)
end.</lang>
end.</syntaxhighlight>


=={{header|PDP-8 Assembly}}==
=={{header|PDP-8 Assembly}}==
Line 6,955: Line 6,955:
Runs on SimH, or any PDP-8 with an EAE
Runs on SimH, or any PDP-8 with an EAE


<lang assembly>
<syntaxhighlight lang="assembly">
/--------------------------------------------------------
/--------------------------------------------------------
/THIS PROGRAM PRINTS THE INTEGERS FROM 1 TO 100 (INCL).
/THIS PROGRAM PRINTS THE INTEGERS FROM 1 TO 100 (INCL).
Line 7,089: Line 7,089:
CR; LF; EOT
CR; LF; EOT
$
$
</syntaxhighlight>
</lang>


Output:
Output:
Line 7,207: Line 7,207:
=={{header|Peloton}}==
=={{header|Peloton}}==
Variable-length padded English dialect
Variable-length padded English dialect
<lang sgml><# DEFINE USERDEFINEDROUTINE LITERAL>__FizzBuzz|<# SUPPRESSAUTOMATICWHITESPACE>
<syntaxhighlight lang="sgml"><# DEFINE USERDEFINEDROUTINE LITERAL>__FizzBuzz|<# SUPPRESSAUTOMATICWHITESPACE>
<# TEST ISITMODULUSZERO PARAMETER LITERAL>1|3</#>
<# TEST ISITMODULUSZERO PARAMETER LITERAL>1|3</#>
<# TEST ISITMODULUSZERO PARAMETER LITERAL>1|5</#>
<# TEST ISITMODULUSZERO PARAMETER LITERAL>1|5</#>
Line 7,215: Line 7,215:
<# NEITHER><# SAY PARAMETER>1</#></#>
<# NEITHER><# SAY PARAMETER>1</#></#>
</#></#>
</#></#>
<# ITERATE FORITERATION LITERAL LITERAL>100|<# ACT USERDEFINEDROUTINE POSITION FORITERATION>__FizzBuzz|...</#> </#></lang>
<# ITERATE FORITERATION LITERAL LITERAL>100|<# ACT USERDEFINEDROUTINE POSITION FORITERATION>__FizzBuzz|...</#> </#></syntaxhighlight>
Fixed-length English dialect
Fixed-length English dialect
<lang sgml><@ DEFUDRLIT>__FizzBuzz|<@ SAW>
<syntaxhighlight lang="sgml"><@ DEFUDRLIT>__FizzBuzz|<@ SAW>
<@ TSTMD0PARLIT>1|3</@>
<@ TSTMD0PARLIT>1|3</@>
<@ TSTMD0PARLIT>1|5</@>
<@ TSTMD0PARLIT>1|5</@>
Line 7,225: Line 7,225:
<@ NTH><@ SAYPAR>1</@></@>
<@ NTH><@ SAYPAR>1</@></@>
</@></@>
</@></@>
<@ ITEFORLITLIT>100|<@ ACTUDRPOSFOR>__FizzBuzz|...</@> </@></lang>
<@ ITEFORLITLIT>100|<@ ACTUDRPOSFOR>__FizzBuzz|...</@> </@></syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>
<syntaxhighlight lang="perl">
use strict;
use strict;
use warnings;
use warnings;
Line 7,238: Line 7,238:
: $i % 5 == 0 ? "Buzz"
: $i % 5 == 0 ? "Buzz"
: $i;
: $i;
}</lang>
}</syntaxhighlight>


More concisely:
More concisely:


<lang perl>print 'Fizz'x!($_ % 3) . 'Buzz'x!($_ % 5) || $_, "\n" for 1 .. 100;</lang>
<syntaxhighlight lang="perl">print 'Fizz'x!($_ % 3) . 'Buzz'x!($_ % 5) || $_, "\n" for 1 .. 100;</syntaxhighlight>


For code-golfing:
For code-golfing:


<lang perl>print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..1e2</lang>
<syntaxhighlight lang="perl">print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..1e2</syntaxhighlight>


For array of values:
For array of values:


<lang perl>map((Fizz)[$_%3].(Buzz)[$_%5]||$_,1..100);</lang>
<syntaxhighlight lang="perl">map((Fizz)[$_%3].(Buzz)[$_%5]||$_,1..100);</syntaxhighlight>


Cheating:
Cheating:


<lang perl>
<syntaxhighlight lang="perl">
use feature "say";
use feature "say";


@a = ("FizzBuzz", 0, 0, "Fizz", 0, "Buzz", "Fizz", 0, 0, "Fizz", "Buzz", 0, "Fizz");
@a = ("FizzBuzz", 0, 0, "Fizz", 0, "Buzz", "Fizz", 0, 0, "Fizz", "Buzz", 0, "Fizz");


say $a[$_ % 15] || $_ for 1..100;</lang>
say $a[$_ % 15] || $_ for 1..100;</syntaxhighlight>


as a subroutine:
as a subroutine:


<lang perl>
<syntaxhighlight lang="perl">
sub fizz_buzz {
sub fizz_buzz {
join("\n", map {
join("\n", map {
Line 7,275: Line 7,275:
}
}
print fizz_buzz;
print fizz_buzz;
</syntaxhighlight>
</lang>


By transforming a list:
By transforming a list:


<lang perl>
<syntaxhighlight lang="perl">
@FB1 = (1..100);
@FB1 = (1..100);
@FB2 = map{!($_%3 or $_%5)?'FizzBuzz': $_}@FB1;
@FB2 = map{!($_%3 or $_%5)?'FizzBuzz': $_}@FB1;
Line 7,286: Line 7,286:
@FB5 = map{$_."\n"}@FB4;
@FB5 = map{$_."\n"}@FB4;
print @FB5;
print @FB5;
</syntaxhighlight>
</lang>


=={{header|Phix}}==
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{libheader|Phix/basics}}
{{trans|C}}
{{trans|C}}
<!--<lang Phix>-->
<!--<syntaxhighlight lang="phix">-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{<span style="color: #008000;">"%d\n"<span style="color: #0000FF;">,<span style="color: #008000;">"Fizz\n"<span style="color: #0000FF;">,<span style="color: #008000;">"Buzz\n"<span style="color: #0000FF;">,<span style="color: #008000;">"FizzBuzz\n"<span style="color: #0000FF;">}</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">x</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{<span style="color: #008000;">"%d\n"<span style="color: #0000FF;">,<span style="color: #008000;">"Fizz\n"<span style="color: #0000FF;">,<span style="color: #008000;">"Buzz\n"<span style="color: #0000FF;">,<span style="color: #008000;">"FizzBuzz\n"<span style="color: #0000FF;">}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i<span style="color: #0000FF;">=<span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">100</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i<span style="color: #0000FF;">=<span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">100</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #000000;">x<span style="color: #0000FF;">[<span style="color: #000000;">1<span style="color: #0000FF;">+<span style="color: #0000FF;">(<span style="color: #7060A8;">remainder<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">3<span style="color: #0000FF;">)<span style="color: #0000FF;">=<span style="color: #000000;">0<span style="color: #0000FF;">)<span style="color: #0000FF;">+<span style="color: #000000;">2<span style="color: #0000FF;">*<span style="color: #0000FF;">(<span style="color: #7060A8;">remainder<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">5<span style="color: #0000FF;">)<span style="color: #0000FF;">=<span style="color: #000000;">0<span style="color: #0000FF;">)<span style="color: #0000FF;">]<span style="color: #0000FF;">,<span style="color: #000000;">i<span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #000000;">x<span style="color: #0000FF;">[<span style="color: #000000;">1<span style="color: #0000FF;">+<span style="color: #0000FF;">(<span style="color: #7060A8;">remainder<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">3<span style="color: #0000FF;">)<span style="color: #0000FF;">=<span style="color: #000000;">0<span style="color: #0000FF;">)<span style="color: #0000FF;">+<span style="color: #000000;">2<span style="color: #0000FF;">*<span style="color: #0000FF;">(<span style="color: #7060A8;">remainder<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">5<span style="color: #0000FF;">)<span style="color: #0000FF;">=<span style="color: #000000;">0<span style="color: #0000FF;">)<span style="color: #0000FF;">]<span style="color: #0000FF;">,<span style="color: #000000;">i<span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for
<span style="color: #008080;">end</span> <span style="color: #008080;">for
<!--</lang>-->
<!--</syntaxhighlight>-->
Two variants with tabulated output:
Two variants with tabulated output:
<!--<lang Phix>-->
<!--<syntaxhighlight lang="phix">-->
<span style="color: #008080;">function</span> <span style="color: #000000;">f<span style="color: #0000FF;">(<span style="color: #004080;">integer</span> <span style="color: #000000;">i<span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">f<span style="color: #0000FF;">(<span style="color: #004080;">integer</span> <span style="color: #000000;">i<span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">idx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1<span style="color: #0000FF;">+<span style="color: #0000FF;">(<span style="color: #7060A8;">remainder<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">3<span style="color: #0000FF;">)<span style="color: #0000FF;">=<span style="color: #000000;">0<span style="color: #0000FF;">)<span style="color: #0000FF;">+<span style="color: #000000;">2<span style="color: #0000FF;">*<span style="color: #0000FF;">(<span style="color: #7060A8;">remainder<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">5<span style="color: #0000FF;">)<span style="color: #0000FF;">=<span style="color: #000000;">0<span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">idx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1<span style="color: #0000FF;">+<span style="color: #0000FF;">(<span style="color: #7060A8;">remainder<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">3<span style="color: #0000FF;">)<span style="color: #0000FF;">=<span style="color: #000000;">0<span style="color: #0000FF;">)<span style="color: #0000FF;">+<span style="color: #000000;">2<span style="color: #0000FF;">*<span style="color: #0000FF;">(<span style="color: #7060A8;">remainder<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">5<span style="color: #0000FF;">)<span style="color: #0000FF;">=<span style="color: #000000;">0<span style="color: #0000FF;">)</span>
Line 7,304: Line 7,304:
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #7060A8;">join_by<span style="color: #0000FF;">(<span style="color: #7060A8;">apply<span style="color: #0000FF;">(<span style="color: #7060A8;">tagset<span style="color: #0000FF;">(<span style="color: #000000;">100<span style="color: #0000FF;">)<span style="color: #0000FF;">,<span style="color: #000000;">f<span style="color: #0000FF;">)<span style="color: #0000FF;">,<span style="color: #000000;">10<span style="color: #0000FF;">,<span style="color: #000000;">10<span style="color: #0000FF;">)<span style="color: #0000FF;">)
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #7060A8;">join_by<span style="color: #0000FF;">(<span style="color: #7060A8;">apply<span style="color: #0000FF;">(<span style="color: #7060A8;">tagset<span style="color: #0000FF;">(<span style="color: #000000;">100<span style="color: #0000FF;">)<span style="color: #0000FF;">,<span style="color: #000000;">f<span style="color: #0000FF;">)<span style="color: #0000FF;">,<span style="color: #000000;">10<span style="color: #0000FF;">,<span style="color: #000000;">10<span style="color: #0000FF;">)<span style="color: #0000FF;">)
<!--</lang>-->
<!--</syntaxhighlight>-->
(output same as below)
(output same as below)
<!--<lang Phix>-->
<!--<syntaxhighlight lang="phix">-->
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply<span style="color: #0000FF;">(<span style="color: #004600;">true<span style="color: #0000FF;">,<span style="color: #7060A8;">sprintf<span style="color: #0000FF;">,<span style="color: #0000FF;">{<span style="color: #0000FF;">{<span style="color: #008000;">"%-8d"<span style="color: #0000FF;">}<span style="color: #0000FF;">,<span style="color: #7060A8;">tagset<span style="color: #0000FF;">(<span style="color: #000000;">100<span style="color: #0000FF;">)<span style="color: #0000FF;">}<span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply<span style="color: #0000FF;">(<span style="color: #004600;">true<span style="color: #0000FF;">,<span style="color: #7060A8;">sprintf<span style="color: #0000FF;">,<span style="color: #0000FF;">{<span style="color: #0000FF;">{<span style="color: #008000;">"%-8d"<span style="color: #0000FF;">}<span style="color: #0000FF;">,<span style="color: #7060A8;">tagset<span style="color: #0000FF;">(<span style="color: #000000;">100<span style="color: #0000FF;">)<span style="color: #0000FF;">}<span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i<span style="color: #0000FF;">=<span style="color: #000000;">3</span> <span style="color: #008080;">to</span> <span style="color: #000000;">100</span> <span style="color: #008080;">by</span> <span style="color: #000000;">3</span> <span style="color: #008080;">do</span> <span style="color: #000000;">s<span style="color: #0000FF;">[<span style="color: #000000;">i<span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Fizz "</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i<span style="color: #0000FF;">=<span style="color: #000000;">3</span> <span style="color: #008080;">to</span> <span style="color: #000000;">100</span> <span style="color: #008080;">by</span> <span style="color: #000000;">3</span> <span style="color: #008080;">do</span> <span style="color: #000000;">s<span style="color: #0000FF;">[<span style="color: #000000;">i<span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Fizz "</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
Line 7,312: Line 7,312:
<span style="color: #008080;">for</span> <span style="color: #000000;">i<span style="color: #0000FF;">=<span style="color: #000000;">15</span> <span style="color: #008080;">to</span> <span style="color: #000000;">100</span> <span style="color: #008080;">by</span> <span style="color: #000000;">15</span> <span style="color: #008080;">do</span> <span style="color: #000000;">s<span style="color: #0000FF;">[<span style="color: #000000;">i<span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"FizzBuzz"</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i<span style="color: #0000FF;">=<span style="color: #000000;">15</span> <span style="color: #008080;">to</span> <span style="color: #000000;">100</span> <span style="color: #008080;">by</span> <span style="color: #000000;">15</span> <span style="color: #008080;">do</span> <span style="color: #000000;">s<span style="color: #0000FF;">[<span style="color: #000000;">i<span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"FizzBuzz"</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #7060A8;">join_by<span style="color: #0000FF;">(<span style="color: #000000;">s<span style="color: #0000FF;">,<span style="color: #000000;">10<span style="color: #0000FF;">,<span style="color: #000000;">10<span style="color: #0000FF;">)<span style="color: #0000FF;">)
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #7060A8;">join_by<span style="color: #0000FF;">(<span style="color: #000000;">s<span style="color: #0000FF;">,<span style="color: #000000;">10<span style="color: #0000FF;">,<span style="color: #000000;">10<span style="color: #0000FF;">)<span style="color: #0000FF;">)
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 7,327: Line 7,327:
</pre>
</pre>
Grotesquely inefficient (non-tabulated output), just for fun. Can you do worse, yet keep it semi-plausibile that someone might have actually earnestly written it?
Grotesquely inefficient (non-tabulated output), just for fun. Can you do worse, yet keep it semi-plausibile that someone might have actually earnestly written it?
<!--<lang Phix>-->
<!--<syntaxhighlight lang="phix">-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">threes</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">tagset<span style="color: #0000FF;">(<span style="color: #000000;">100<span style="color: #0000FF;">,<span style="color: #000000;">0<span style="color: #0000FF;">,<span style="color: #000000;">3<span style="color: #0000FF;">)<span style="color: #0000FF;">,</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">threes</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">tagset<span style="color: #0000FF;">(<span style="color: #000000;">100<span style="color: #0000FF;">,<span style="color: #000000;">0<span style="color: #0000FF;">,<span style="color: #000000;">3<span style="color: #0000FF;">)<span style="color: #0000FF;">,</span>
<span style="color: #000000;">fives</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">tagset<span style="color: #0000FF;">(<span style="color: #000000;">100<span style="color: #0000FF;">,<span style="color: #000000;">0<span style="color: #0000FF;">,<span style="color: #000000;">5<span style="color: #0000FF;">)<span style="color: #0000FF;">,</span>
<span style="color: #000000;">fives</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">tagset<span style="color: #0000FF;">(<span style="color: #000000;">100<span style="color: #0000FF;">,<span style="color: #000000;">0<span style="color: #0000FF;">,<span style="color: #000000;">5<span style="color: #0000FF;">)<span style="color: #0000FF;">,</span>
Line 7,347: Line 7,347:
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #008000;">"\n"<span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #008000;">"\n"<span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for
<span style="color: #008080;">end</span> <span style="color: #008080;">for
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PHL}}==
=={{header|PHL}}==
{{trans|C}}
{{trans|C}}
<lang phl>module fizzbuzz;
<syntaxhighlight lang="phl">module fizzbuzz;


extern printf;
extern printf;
Line 7,372: Line 7,372:
return 0;
return 0;
]</lang>
]</syntaxhighlight>


=={{header|PHP}}==
=={{header|PHP}}==
===if/else ladder approach===
===if/else ladder approach===
<lang php><?php
<syntaxhighlight lang="php"><?php
for ($i = 1; $i <= 100; $i++)
for ($i = 1; $i <= 100; $i++)
{
{
Line 7,388: Line 7,388:
echo "$i\n";
echo "$i\n";
}
}
?></lang>
?></syntaxhighlight>
===Concatenation approach===
===Concatenation approach===
Uses PHP's concatenation operator (.=) to build the output string. The concatenation operator allows us to add data to the end of a string without overwriting the whole string. Since Buzz will always appear if our number is divisible by five, and Buzz is the second part of "FizzBuzz", we can simply append "Buzz" to our string.
Uses PHP's concatenation operator (.=) to build the output string. The concatenation operator allows us to add data to the end of a string without overwriting the whole string. Since Buzz will always appear if our number is divisible by five, and Buzz is the second part of "FizzBuzz", we can simply append "Buzz" to our string.


In contrast to the if-else ladder, this method lets us skip the check to see if $i is divisible by both 3 and 5 (i.e. 15). However, we get the added complexity of needing to reset $str to an empty string (not necessary in some other languages), and we also need a separate if statement to check to see if our string is empty, so we know if $i was not divisible by 3 or 5.
In contrast to the if-else ladder, this method lets us skip the check to see if $i is divisible by both 3 and 5 (i.e. 15). However, we get the added complexity of needing to reset $str to an empty string (not necessary in some other languages), and we also need a separate if statement to check to see if our string is empty, so we know if $i was not divisible by 3 or 5.
<lang php><?php
<syntaxhighlight lang="php"><?php
for ( $i = 1; $i <= 100; ++$i )
for ( $i = 1; $i <= 100; ++$i )
{
{
Line 7,409: Line 7,409:
echo $str . "\n";
echo $str . "\n";
}
}
?></lang>
?></syntaxhighlight>
===Concatenation approach without if-s===
===Concatenation approach without if-s===
<lang php><?php
<syntaxhighlight lang="php"><?php
for (
for (
$i = 0;
$i = 0;
Line 7,418: Line 7,418:
)
)
echo $o ? : $i, PHP_EOL;
echo $o ? : $i, PHP_EOL;
?></lang>
?></syntaxhighlight>


===One Liner Approach===
===One Liner Approach===
<lang php><?php
<syntaxhighlight lang="php"><?php
for($i = 1; $i <= 100 and print(($i % 15 ? $i % 5 ? $i % 3 ? $i : 'Fizz' : 'Buzz' : 'FizzBuzz') . "\n"); ++$i);
for($i = 1; $i <= 100 and print(($i % 15 ? $i % 5 ? $i % 3 ? $i : 'Fizz' : 'Buzz' : 'FizzBuzz') . "\n"); ++$i);
?></lang>
?></syntaxhighlight>


===Compact One Liner Approach===
===Compact One Liner Approach===
<lang php>for($i=0;$i++<100;)echo($i%3?'':'Fizz').($i%5?'':'Buzz')?:$i,"\n";</lang>
<syntaxhighlight lang="php">for($i=0;$i++<100;)echo($i%3?'':'Fizz').($i%5?'':'Buzz')?:$i,"\n";</syntaxhighlight>
===Array One Liner Approach===
===Array One Liner Approach===
<lang php>for($i = 0; $i++ < 100;) echo [$i, 'Fizz', 'Buzz', 'FizzBuzz'][!($i % 3) + 2 * !($i % 5)], "\n";</lang>
<syntaxhighlight lang="php">for($i = 0; $i++ < 100;) echo [$i, 'Fizz', 'Buzz', 'FizzBuzz'][!($i % 3) + 2 * !($i % 5)], "\n";</syntaxhighlight>


=={{header|Picat}}==
=={{header|Picat}}==
Line 7,436: Line 7,436:


===Using a map===
===Using a map===
<lang Picat>fizzbuzz_map =>
<syntaxhighlight lang="picat">fizzbuzz_map =>
println(fizzbuzz_map),
println(fizzbuzz_map),
FB = [I : I in 1..100],
FB = [I : I in 1..100],
Line 7,445: Line 7,445:
end
end
end,
end,
println(FB).</lang>
println(FB).</syntaxhighlight>


===Using a template for the pattern===
===Using a template for the pattern===
<lang Picat>fizzbuzz_template1 =>
<syntaxhighlight lang="picat">fizzbuzz_template1 =>
println(fizzbuzz_template1),
println(fizzbuzz_template1),
N = 100,
N = 100,
Line 7,457: Line 7,457:
print(" ")
print(" ")
end,
end,
nl.</lang>
nl.</syntaxhighlight>


===Another version with templates===
===Another version with templates===
<lang Picat>fizzbuzz_template2 =>
<syntaxhighlight lang="picat">fizzbuzz_template2 =>
println(fizzbuzz_template2),
println(fizzbuzz_template2),
N = 100,
N = 100,
Line 7,472: Line 7,472:
printf("%w ", cond(var(F[I]),I, F[I]))
printf("%w ", cond(var(F[I]),I, F[I]))
end,
end,
nl.</lang>
nl.</syntaxhighlight>




Below are some versions for identifying the FizzBuzziness of a number.
Below are some versions for identifying the FizzBuzziness of a number.
To be used with the following general wrapper:
To be used with the following general wrapper:
<lang Picat>fizzbuzz(Goal) =>
<syntaxhighlight lang="picat">fizzbuzz(Goal) =>
println(Goal),
println(Goal),
foreach(I in 1..100)
foreach(I in 1..100)
printf("%w ", apply(Goal,I))
printf("%w ", apply(Goal,I))
end,
end,
nl.</lang>
nl.</syntaxhighlight>


===Plain imperative approach: if/else===
===Plain imperative approach: if/else===
<lang Picat>fb1(I) = V =>
<syntaxhighlight lang="picat">fb1(I) = V =>
V = I.to_string(),
V = I.to_string(),
if I mod 15 == 0 then V := "FizzBuzz"
if I mod 15 == 0 then V := "FizzBuzz"
elseif I mod 3 == 0 then V := "Fizz"
elseif I mod 3 == 0 then V := "Fizz"
elseif I mod 5 == 0 then V := "Buzz"
elseif I mod 5 == 0 then V := "Buzz"
end.</lang>
end.</syntaxhighlight>


===Pattern matching + conditions in head===
===Pattern matching + conditions in head===
<lang Picat>fb2(I) = "FizzBuzz", I mod 15 == 0 => true.
<syntaxhighlight lang="picat">fb2(I) = "FizzBuzz", I mod 15 == 0 => true.
fb2(I) = "Fizz", I mod 3 == 0 => true.
fb2(I) = "Fizz", I mod 3 == 0 => true.
fb2(I) = "Buzz", I mod 5 == 0 => true.
fb2(I) = "Buzz", I mod 5 == 0 => true.
fb2(I) = I.to_string() => true.</lang>
fb2(I) = I.to_string() => true.</syntaxhighlight>


===Another pattern matching approach===
===Another pattern matching approach===
<lang Picat>fb3(I) = fb3b(I, I mod 3, I mod 5).
<syntaxhighlight lang="picat">fb3(I) = fb3b(I, I mod 3, I mod 5).
fb3b(_I,0,0) = "FizzBuzz".
fb3b(_I,0,0) = "FizzBuzz".
fb3b(_I,_,0) = "Buzz".
fb3b(_I,_,0) = "Buzz".
fb3b(_I,0,_) = "Fizz".
fb3b(_I,0,_) = "Fizz".
fb3b(I,_,_) = I.</lang>
fb3b(I,_,_) = I.</syntaxhighlight>


===Using cond/3 and string concatenation===
===Using cond/3 and string concatenation===
<lang Picat>fb4(I) = cond(I mod 3 == 0, "Fizz", "") ++
<syntaxhighlight lang="picat">fb4(I) = cond(I mod 3 == 0, "Fizz", "") ++
cond(I mod 5 == 0, "Buzz", "") ++
cond(I mod 5 == 0, "Buzz", "") ++
cond(not ((I mod 3 == 0; I mod 5==0)), I.to_string(), "").</lang>
cond(not ((I mod 3 == 0; I mod 5==0)), I.to_string(), "").</syntaxhighlight>


===Recursive function (conditions in head)===
===Recursive function (conditions in head)===
<lang Picat>fizzbuzz_rec =>
<syntaxhighlight lang="picat">fizzbuzz_rec =>
print(fizzbuzz_rec),
print(fizzbuzz_rec),
fb5(100,[],L),
fb5(100,[],L),
Line 7,525: Line 7,525:
fb5(N-1,L1 ++ ["Fizz"], L).
fb5(N-1,L1 ++ ["Fizz"], L).
fb5(N,L1,L), N mod 3 > 0, N mod 5 > 0 =>
fb5(N,L1,L), N mod 3 > 0, N mod 5 > 0 =>
fb5(N-1,L1 ++ [N.to_string()], L).</lang>
fb5(N-1,L1 ++ [N.to_string()], L).</syntaxhighlight>


===Golfing style===
===Golfing style===
<lang Picat>fizzbuzz_golf =>
<syntaxhighlight lang="picat">fizzbuzz_golf =>
println(fizzbuzz_golf),
println(fizzbuzz_golf),
[cond(P=="",I,P):I in 1..100,(I mod 3==0->P="Fizz";P=""),(I mod 5==0->P:=P++"Buzz";true)].println().
[cond(P=="",I,P):I in 1..100,(I mod 3==0->P="Fizz";P=""),(I mod 5==0->P:=P++"Buzz";true)].println().
</syntaxhighlight>
</lang>


===Planner version===
===Planner version===
Picat has support for "classic" planning problems. The <code>planner</code> module must be imported.
Picat has support for "classic" planning problems. The <code>planner</code> module must be imported.
<lang Picat>import planner.
<syntaxhighlight lang="picat">import planner.
fizzbuzz_planner =>
fizzbuzz_planner =>
println(fizzbuzz_planner),
println(fizzbuzz_planner),
Line 7,567: Line 7,567:
Move = H.to_string(),
Move = H.to_string(),
To = H-1,
To = H-1,
Cost = 1.</lang>
Cost = 1.</syntaxhighlight>




Here we test everything.
Here we test everything.
<lang Picat>go =>
<syntaxhighlight lang="picat">go =>
fizzbuzz_map,
fizzbuzz_map,
fizzbuzz_template1,
fizzbuzz_template1,
Line 7,583: Line 7,583:
call(fizzbuzz,FB)
call(fizzbuzz,FB)
end,
end,
nl.</lang>
nl.</syntaxhighlight>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
We could simply use '[http://software-lab.de/doc/refA.html#at at]' here:
We could simply use '[http://software-lab.de/doc/refA.html#at at]' here:
<lang PicoLisp>(for N 100
<syntaxhighlight lang="picolisp">(for N 100
(prinl
(prinl
(or (pack (at (0 . 3) "Fizz") (at (0 . 5) "Buzz")) N) ) )
(or (pack (at (0 . 3) "Fizz") (at (0 . 5) "Buzz")) N) ) )
Line 7,594: Line 7,594:
# Rest of the times 'N' is printed as it loops in 'for'.
# Rest of the times 'N' is printed as it loops in 'for'.


</syntaxhighlight>
</lang>
Or do it the standard way:
Or do it the standard way:
<lang PicoLisp>(for N 100
<syntaxhighlight lang="picolisp">(for N 100
(prinl
(prinl
(cond
(cond
Line 7,602: Line 7,602:
((=0 (% N 3)) "Fizz")
((=0 (% N 3)) "Fizz")
((=0 (% N 5)) "Buzz")
((=0 (% N 5)) "Buzz")
(T N) ) ) )</lang>
(T N) ) ) )</syntaxhighlight>


=={{header|Pike}}==
=={{header|Pike}}==
<lang pike>int main(){
<syntaxhighlight lang="pike">int main(){
for(int i = 1; i <= 100; i++) {
for(int i = 1; i <= 100; i++) {
if(i % 15 == 0) {
if(i % 15 == 0) {
Line 7,617: Line 7,617:
}
}
}
}
}</lang>
}</syntaxhighlight>


=={{header|PILOT}}==
=={{header|PILOT}}==
<lang pilot>C :i = 0
<syntaxhighlight lang="pilot">C :i = 0
*loop
*loop
C :i = i + 1
C :i = i + 1
Line 7,642: Line 7,642:
J : *loop
J : *loop
*finished
*finished
END:</lang>
END:</syntaxhighlight>


=={{header|PIR}}==
=={{header|PIR}}==
{{works with|Parrot|tested with 2.4.0}}
{{works with|Parrot|tested with 2.4.0}}
<lang pir>.sub main :main
<syntaxhighlight lang="pir">.sub main :main
.local int f
.local int f
.local int mf
.local int mf
Line 7,679: Line 7,679:
DONE:
DONE:
end
end
.end</lang>
.end</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang PL/I>do i = 1 to 100;
<syntaxhighlight lang="pl/i">do i = 1 to 100;
select;
select;
when (mod(i,15) = 0) put skip list ('FizzBuzz');
when (mod(i,15) = 0) put skip list ('FizzBuzz');
Line 7,689: Line 7,689:
otherwise put skip list (i);
otherwise put skip list (i);
end;
end;
end;</lang>
end;</syntaxhighlight>


=={{header|PL/M}}==
=={{header|PL/M}}==
<lang plm>100H:
<syntaxhighlight lang="plm">100H:


/* DECLARE OUTPUT IN TERMS OF CP/M -
/* DECLARE OUTPUT IN TERMS OF CP/M -
Line 7,736: Line 7,736:
/* EXIT TO CP/M */
/* EXIT TO CP/M */
CALL BDOS(0,0);
CALL BDOS(0,0);
EOF</lang>
EOF</syntaxhighlight>


=={{header|PL/SQL}}==
=={{header|PL/SQL}}==
<lang plsql>begin
<syntaxhighlight lang="plsql">begin
for i in 1 .. 100
for i in 1 .. 100
loop
loop
Line 7,753: Line 7,753:
end case;
end case;
end loop;
end loop;
end;</lang>
end;</syntaxhighlight>


=={{header|Pony}}==
=={{header|Pony}}==
<lang pony>use "collections"
<syntaxhighlight lang="pony">use "collections"
actor Main
actor Main
Line 7,773: Line 7,773:
else
else
n.string()
n.string()
end</lang>
end</syntaxhighlight>


=={{header|Pop11}}==
=={{header|Pop11}}==
<lang pop11>lvars str;
<syntaxhighlight lang="pop11">lvars str;
for i from 1 to 100 do
for i from 1 to 100 do
if i rem 15 = 0 then
if i rem 15 = 0 then
Line 7,788: Line 7,788:
endif;
endif;
printf(str, '%s\n');
printf(str, '%s\n');
endfor;</lang>
endfor;</syntaxhighlight>


=={{header|PostScript}}==
=={{header|PostScript}}==
<lang postscript>1 1 100 {
<syntaxhighlight lang="postscript">1 1 100 {
/c false def
/c false def
dup 3 mod 0 eq { (Fizz) print /c true def } if
dup 3 mod 0 eq { (Fizz) print /c true def } if
Line 7,797: Line 7,797:
c {pop}{( ) cvs print} ifelse
c {pop}{( ) cvs print} ifelse
(\n) print
(\n) print
} for</lang>
} for</syntaxhighlight>
or...
or...
<lang postscript>/fizzdict 100 dict def
<syntaxhighlight lang="postscript">/fizzdict 100 dict def
fizzdict begin
fizzdict begin
/notmod{ ( ) cvs } def
/notmod{ ( ) cvs } def
Line 7,809: Line 7,809:
1 1 100 { mod15} for
1 1 100 { mod15} for
1 1 100 { dup currentdict exch known { currentdict exch get}{notmod} ifelse print (\n) print} for
1 1 100 { dup currentdict exch known { currentdict exch get}{notmod} ifelse print (\n) print} for
end</lang>
end</syntaxhighlight>


=={{header|Potion}}==
=={{header|Potion}}==
<lang lua>
<syntaxhighlight lang="lua">
1 to 100 (a):
1 to 100 (a):
if (a % 15 == 0):
if (a % 15 == 0):
Line 7,821: Line 7,821:
'Buzz'.
'Buzz'.
else: a. string print
else: a. string print
"\n" print.</lang>
"\n" print.</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
===Straightforward, looping===
===Straightforward, looping===
<lang powershell>for ($i = 1; $i -le 100; $i++) {
<syntaxhighlight lang="powershell">for ($i = 1; $i -le 100; $i++) {
if ($i % 15 -eq 0) {
if ($i % 15 -eq 0) {
"FizzBuzz"
"FizzBuzz"
Line 7,835: Line 7,835:
$i
$i
}
}
}</lang>
}</syntaxhighlight>
===Pipeline, Switch===
===Pipeline, Switch===
<lang powershell>$txt=$null
<syntaxhighlight lang="powershell">$txt=$null
1..100 | ForEach-Object {
1..100 | ForEach-Object {
switch ($_) {
switch ($_) {
Line 7,844: Line 7,844:
$_ { if($txt) { $txt } else { $_ }; $txt=$null }
$_ { if($txt) { $txt } else { $_ }; $txt=$null }
}
}
}</lang>
}</syntaxhighlight>


===Concatenation===
===Concatenation===
{{trans|C#}}
{{trans|C#}}
<lang powershell>1..100 | ForEach-Object {
<syntaxhighlight lang="powershell">1..100 | ForEach-Object {
$s = ''
$s = ''
if ($_ % 3 -eq 0) { $s += "Fizz" }
if ($_ % 3 -eq 0) { $s += "Fizz" }
Line 7,854: Line 7,854:
if (-not $s) { $s = $_ }
if (-not $s) { $s = $_ }
$s
$s
}</lang>
}</syntaxhighlight>


===Piping, Evaluation, Concatenation===
===Piping, Evaluation, Concatenation===
<lang powershell>
<syntaxhighlight lang="powershell">
1..100 | % {write-host("$(if(($_ % 3 -ne 0) -and ($_ % 5 -ne 0)){$_})$(if($_ % 3 -eq 0){"Fizz"})$(if($_ % 5 -eq 0){"Buzz"})")}
1..100 | % {write-host("$(if(($_ % 3 -ne 0) -and ($_ % 5 -ne 0)){$_})$(if($_ % 3 -eq 0){"Fizz"})$(if($_ % 5 -eq 0){"Buzz"})")}
</syntaxhighlight>
</lang>


===Filter, Piping, Regex Matching, Array Auto-Selection===
===Filter, Piping, Regex Matching, Array Auto-Selection===
<lang powershell>
<syntaxhighlight lang="powershell">
filter fizz-buzz{
filter fizz-buzz{
@(
@(
Line 7,877: Line 7,877:


1..100 | fizz-buzz
1..100 | fizz-buzz
</syntaxhighlight>
</lang>


===String Manipulation with Regex===
===String Manipulation with Regex===
<lang powershell>
<syntaxhighlight lang="powershell">
(1..100 -join "`n") + "`nFizzBuzz" -replace '(?ms)(^([369]([369]|(?=0|$))|[258][147]|[147]([28]|(?=5))))(?=[05]?$.*(Fizz))|(((?<=[369])|[^369])0+|((?<=[147\s])|[^147\s])5)(?=$.*(Buzz))|FizzBuzz', '$5$9'
(1..100 -join "`n") + "`nFizzBuzz" -replace '(?ms)(^([369]([369]|(?=0|$))|[258][147]|[147]([28]|(?=5))))(?=[05]?$.*(Fizz))|(((?<=[369])|[^369])0+|((?<=[147\s])|[^147\s])5)(?=$.*(Buzz))|FizzBuzz', '$5$9'
</syntaxhighlight>
</lang>


=={{header|Processing}}==
=={{header|Processing}}==
Line 7,888: Line 7,888:
Reserved variable "width" in Processing is 100 pixels by default, suitable for this FizzBuzz exercise.
Reserved variable "width" in Processing is 100 pixels by default, suitable for this FizzBuzz exercise.
Accordingly, range is pixel index from 0 to 99.
Accordingly, range is pixel index from 0 to 99.
<lang Processing>for (int i = 0; i < width; i++) {
<syntaxhighlight lang="processing">for (int i = 0; i < width; i++) {
if (i % 3 == 0 && i % 5 == 0) {
if (i % 3 == 0 && i % 5 == 0) {
stroke(255, 255, 0);
stroke(255, 255, 0);
Line 7,906: Line 7,906:
}
}
line(i, 0, i, height);
line(i, 0, i, height);
}</lang>
}</syntaxhighlight>
===Console & Visualization, Ternary===
===Console & Visualization, Ternary===
<lang Processing>for (int i = 0; i < width; i++) {
<syntaxhighlight lang="processing">for (int i = 0; i < width; i++) {
stroke((i % 5 == 0 && i % 3 == 0) ? #FFFF00 : (i % 5 == 0) ? #00FF00 : (i % 3 == 0) ? #FF0000 : #0000FF);
stroke((i % 5 == 0 && i % 3 == 0) ? #FFFF00 : (i % 5 == 0) ? #00FF00 : (i % 3 == 0) ? #FF0000 : #0000FF);
line(i, 0, i, height);
line(i, 0, i, height);
println((i % 5 == 0 && i % 3 == 0) ? "FizzBuzz!" : (i % 5 == 0) ? "Buzz" : (i % 3 == 0) ? "Fizz" : i);
println((i % 5 == 0 && i % 3 == 0) ? "FizzBuzz!" : (i % 5 == 0) ? "Buzz" : (i % 3 == 0) ? "Fizz" : i);
}</lang>
}</syntaxhighlight>
===Console===
===Console===
<lang Processing>for (int i = 1; i <= 100; i++) {
<syntaxhighlight lang="processing">for (int i = 1; i <= 100; i++) {
if (i % 3 == 0) {
if (i % 3 == 0) {
print("Fizz");
print("Fizz");
Line 7,925: Line 7,925:
}
}
print("\n");
print("\n");
}</lang>
}</syntaxhighlight>
===Console, "Futureproof"===
===Console, "Futureproof"===
<lang Processing>for(int i = 1; i <= 100; i++){
<syntaxhighlight lang="processing">for(int i = 1; i <= 100; i++){
String output = "";
String output = "";
Line 7,936: Line 7,936:
if(output == "") output = str(i);
if(output == "") output = str(i);
println(output);
println(output);
}</lang>
}</syntaxhighlight>


All examples produce the same console output:
All examples produce the same console output:
Line 8,047: Line 8,047:
{{works with|SWI Prolog|4.8.0}}
{{works with|SWI Prolog|4.8.0}}
Maybe not the most conventional way to write this in Prolog. The fizzbuzz predicate uses a higher-order predicate and print_item uses the if-then-else construction.
Maybe not the most conventional way to write this in Prolog. The fizzbuzz predicate uses a higher-order predicate and print_item uses the if-then-else construction.
<lang prolog>fizzbuzz :-
<syntaxhighlight lang="prolog">fizzbuzz :-
foreach(between(1, 100, X), print_item(X)).
foreach(between(1, 100, X), print_item(X)).


Line 8,059: Line 8,059:
; print(X)
; print(X)
),
),
nl.</lang>
nl.</syntaxhighlight>
More conventional:
More conventional:
<lang prolog>fizzbuzz(X) :- 0 is X mod 15, write('FizzBuzz').
<syntaxhighlight lang="prolog">fizzbuzz(X) :- 0 is X mod 15, write('FizzBuzz').
fizzbuzz(X) :- 0 is X mod 3, write('Fizz').
fizzbuzz(X) :- 0 is X mod 3, write('Fizz').
fizzbuzz(X) :- 0 is X mod 5, write('Buzz').
fizzbuzz(X) :- 0 is X mod 5, write('Buzz').
fizzbuzz(X) :- write(X).
fizzbuzz(X) :- write(X).


dofizzbuzz :- foreach(between(1, 100, X), (fizzbuzz(X),nl)).</lang>
dofizzbuzz :- foreach(between(1, 100, X), (fizzbuzz(X),nl)).</syntaxhighlight>
Clearer:
Clearer:
<lang prolog>% N /3? /5? V
<syntaxhighlight lang="prolog">% N /3? /5? V
fizzbuzz(_, yes, yes, 'FizzBuzz').
fizzbuzz(_, yes, yes, 'FizzBuzz').
fizzbuzz(_, yes, no, 'Fizz').
fizzbuzz(_, yes, no, 'Fizz').
Line 8,087: Line 8,087:


main :-
main :-
foreach(between(1,100, N), fizz_buzz_or_n(N)).</lang>
foreach(between(1,100, N), fizz_buzz_or_n(N)).</syntaxhighlight>


Using modern Prolog techniques, resulting in idiomatic, highly declarative code:
Using modern Prolog techniques, resulting in idiomatic, highly declarative code:


{{works with|SWI Prolog|8.2.1}} {{works with|Scryer Prolog|0.7.8}}
{{works with|SWI Prolog|8.2.1}} {{works with|Scryer Prolog|0.7.8}}
<lang prolog>
<syntaxhighlight lang="prolog">
% This implementation uses modern Prolog techniques
% This implementation uses modern Prolog techniques
% in order to be an idiomatic solution that uses logical purity, generality and determinism wherever possible:
% in order to be an idiomatic solution that uses logical purity, generality and determinism wherever possible:
Line 8,160: Line 8,160:
eq_t(>, false).
eq_t(>, false).


</syntaxhighlight>
</lang>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
Line 8,166: Line 8,166:


=={{header|Pyret}}==
=={{header|Pyret}}==
<lang pyret>fun fizzbuzz(n :: NumPositive) -> String:
<syntaxhighlight lang="pyret">fun fizzbuzz(n :: NumPositive) -> String:
doc: ```For positive input which is multiples of three return 'Fizz', for the multiples of five return 'Buzz'.
doc: ```For positive input which is multiples of three return 'Fizz', for the multiples of five return 'Buzz'.
For numbers which are multiples of both three and five return 'FizzBuzz'. Otherwise, return the number itself.```
For numbers which are multiples of both three and five return 'FizzBuzz'. Otherwise, return the number itself.```
Line 8,183: Line 8,183:
end
end


range(1, 101).map(fizzbuzz).each(print)</lang>
range(1, 101).map(fizzbuzz).each(print)</syntaxhighlight>


=={{header|Python}}==
=={{header|Python}}==
===Python2: Simple===
===Python2: Simple===
<lang python>for i in xrange(1, 101):
<syntaxhighlight lang="python">for i in xrange(1, 101):
if i % 15 == 0:
if i % 15 == 0:
print "FizzBuzz"
print "FizzBuzz"
Line 8,195: Line 8,195:
print "Buzz"
print "Buzz"
else:
else:
print i</lang>
print i</syntaxhighlight>


===Python3: Simple===
===Python3: Simple===
<lang python>for i in range(1, 101):
<syntaxhighlight lang="python">for i in range(1, 101):
if i % 15 == 0:
if i % 15 == 0:
print("FizzBuzz")
print("FizzBuzz")
Line 8,206: Line 8,206:
print("Buzz")
print("Buzz")
else:
else:
print(i)</lang>
print(i)</syntaxhighlight>


===Python: Simple - no duplication ===
===Python: Simple - no duplication ===
<lang python>for n in range(1,101):
<syntaxhighlight lang="python">for n in range(1,101):
response = ''
response = ''


Line 8,218: Line 8,218:


print(response or n)
print(response or n)
</syntaxhighlight>
</lang>
One liner using string concatenation:
One liner using string concatenation:
<lang python>for i in range(1,101): print("Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i)</lang>
<syntaxhighlight lang="python">for i in range(1,101): print("Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i)</syntaxhighlight>


One liner another code:
One liner another code:
<lang python>for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or i+1)</lang>
<syntaxhighlight lang="python">for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or i+1)</syntaxhighlight>


List Comprehensions:
List Comprehensions:
<lang python>
<syntaxhighlight lang="python">
for n in range(1, 100):
for n in range(1, 100):
fb = ''.join([ denom[1] if n % denom[0] == 0 else '' for denom in [(3,'fizz'),(5,'buzz')] ])
fb = ''.join([ denom[1] if n % denom[0] == 0 else '' for denom in [(3,'fizz'),(5,'buzz')] ])
print fb if fb else n
print fb if fb else n
</syntaxhighlight>
</lang>
Another list comprehension:
Another list comprehension:
<lang python>
<syntaxhighlight lang="python">
print (', '.join([(x%3<1)*'Fizz'+(x%5<1)*'Buzz' or str(x) for x in range(1,101)]))
print (', '.join([(x%3<1)*'Fizz'+(x%5<1)*'Buzz' or str(x) for x in range(1,101)]))
</syntaxhighlight>
</lang>


===Python: List Comprehension (Python 3)===
===Python: List Comprehension (Python 3)===
<lang python>[print("FizzBuzz") if i % 15 == 0 else print("Fizz") if i % 3 == 0 else print("Buzz") if i % 5 == 0 else print(i) for i in range(1,101)]</lang>
<syntaxhighlight lang="python">[print("FizzBuzz") if i % 15 == 0 else print("Fizz") if i % 3 == 0 else print("Buzz") if i % 5 == 0 else print(i) for i in range(1,101)]</syntaxhighlight>


===Python: Lazily===
===Python: Lazily===
You can also create a lazy, unbounded sequence by using generator expressions:
You can also create a lazy, unbounded sequence by using generator expressions:
<lang python>from itertools import cycle, izip, count, islice
<syntaxhighlight lang="python">from itertools import cycle, izip, count, islice


fizzes = cycle([""] * 2 + ["Fizz"])
fizzes = cycle([""] * 2 + ["Fizz"])
Line 8,253: Line 8,253:
# print the first 100
# print the first 100
for i in islice(fizzbuzz, 100):
for i in islice(fizzbuzz, 100):
print i</lang>
print i</syntaxhighlight>




Or equivalently, in terms of map, and Python 3 libraries:
Or equivalently, in terms of map, and Python 3 libraries:
{{Works with|Python|3.7}}
{{Works with|Python|3.7}}
<lang python>'''Fizz buzz'''
<syntaxhighlight lang="python">'''Fizz buzz'''


from itertools import count, cycle, islice
from itertools import count, cycle, islice
Line 8,290: Line 8,290:


if __name__ == '__main__':
if __name__ == '__main__':
main()</lang>
main()</syntaxhighlight>


===Python3.8: With walrus operator===
===Python3.8: With walrus operator===


<lang python>print(*map(lambda n: 'Fizzbuzz '[(i):i+13] if (i := n**4%-15) > -14 else n, range(1,100)))</lang>
<syntaxhighlight lang="python">print(*map(lambda n: 'Fizzbuzz '[(i):i+13] if (i := n**4%-15) > -14 else n, range(1,100)))</syntaxhighlight>


===Python: Math tricks===
===Python: Math tricks===
Numbers ending in 5 or 0 are divisible by 5. Numbers whose digits recursively summed to a single-digit number == 3,6 or 9 are divisible by 3.
Numbers ending in 5 or 0 are divisible by 5. Numbers whose digits recursively summed to a single-digit number == 3,6 or 9 are divisible by 3.
<lang python>
<syntaxhighlight lang="python">
def numsum(n):
def numsum(n):
''' The recursive sum of all digits in a number
''' The recursive sum of all digits in a number
Line 8,311: Line 8,311:
or n
or n
print(response)
print(response)
</syntaxhighlight>
</lang>


===Python3: Super concise: 1 line===
===Python3: Super concise: 1 line===
<lang python>
<syntaxhighlight lang="python">
print(*((lambda x=x: ''.join(chr(c) for c in (102, 105)) + (2 * chr(122)) + ''.join(chr(c) for c in (98, 117)) + (2 * chr(122)) + '\n' if x % (30 >> 1) == 0 else ''.join(chr(c) for c in (102, 105)) + (2 * chr(122)) + '\n' if x % (6 >> 1) == 0 else ''.join(chr(c) for c in (98, 117)) + (2 * chr(122)) + '\n' if x % (10 >> 1) == 0 else str(x) + '\n')() for x in range(1, 101)))
print(*((lambda x=x: ''.join(chr(c) for c in (102, 105)) + (2 * chr(122)) + ''.join(chr(c) for c in (98, 117)) + (2 * chr(122)) + '\n' if x % (30 >> 1) == 0 else ''.join(chr(c) for c in (102, 105)) + (2 * chr(122)) + '\n' if x % (6 >> 1) == 0 else ''.join(chr(c) for c in (98, 117)) + (2 * chr(122)) + '\n' if x % (10 >> 1) == 0 else str(x) + '\n')() for x in range(1, 101)))
</syntaxhighlight>
</lang>


=={{header|Q}}==
=={{header|Q}}==


<syntaxhighlight lang="q">
<lang Q>
q){(sum 1 2*0=x mod/:3 5)'[`$string x;`fizz;`buzz;`fizzbuzz]}1+til 20
q){(sum 1 2*0=x mod/:3 5)'[`$string x;`fizz;`buzz;`fizzbuzz]}1+til 20
`1`2`fizz`4`buzz`fizz`7`8`fizz`buzz`11`fizz`13`14`fizzbuzz`16`17`fizz`19`buzz</lang>
`1`2`fizz`4`buzz`fizz`7`8`fizz`buzz`11`fizz`13`14`fizzbuzz`16`17`fizz`19`buzz</syntaxhighlight>


https://code.kx.com/q/learn/reading/fizzbuzz/
https://code.kx.com/q/learn/reading/fizzbuzz/


=={{header|QB64}}==
=={{header|QB64}}==
<lang qb64>For n = 1 To 100
<syntaxhighlight lang="qb64">For n = 1 To 100
If n Mod 15 = 0 Then
If n Mod 15 = 0 Then
Print "FizzBuzz"
Print "FizzBuzz"
Line 8,337: Line 8,337:
Print n
Print n
End If
End If
Next</lang>
Next</syntaxhighlight>


=={{header|Quackery}}==
=={{header|Quackery}}==
<lang Quackery> [ times
<syntaxhighlight lang="quackery"> [ times
[ i^ 1+
[ i^ 1+
' echo
' echo
Line 8,354: Line 8,354:


say 'First 100 turns in the game of fizzbuzz:' cr cr
say 'First 100 turns in the game of fizzbuzz:' cr cr
100 fizzbuzz cr</lang>
100 fizzbuzz cr</syntaxhighlight>




=={{header|R}}==
=={{header|R}}==
<lang rsplus>xx <- x <- 1:100
<syntaxhighlight lang="rsplus">xx <- x <- 1:100
xx[x %% 3 == 0] <- "Fizz"
xx[x %% 3 == 0] <- "Fizz"
xx[x %% 5 == 0] <- "Buzz"
xx[x %% 5 == 0] <- "Buzz"
xx[x %% 15 == 0] <- "FizzBuzz"
xx[x %% 15 == 0] <- "FizzBuzz"
xx</lang>
xx</syntaxhighlight>


Or, without directly checking for divisibility by 15:
Or, without directly checking for divisibility by 15:
<lang rsplus>xx <- rep("", 100)
<syntaxhighlight lang="rsplus">xx <- rep("", 100)
x <- 1:100
x <- 1:100
xx[x %% 3 == 0] <- paste0(xx[x %% 3 == 0], "Fizz")
xx[x %% 3 == 0] <- paste0(xx[x %% 3 == 0], "Fizz")
xx[x %% 5 == 0] <- paste0(xx[x %% 5 == 0], "Buzz")
xx[x %% 5 == 0] <- paste0(xx[x %% 5 == 0], "Buzz")
xx[xx == ""] <- x[xx == ""]
xx[xx == ""] <- x[xx == ""]
xx</lang>
xx</syntaxhighlight>


Or, (ab)using the vector recycling rule:
Or, (ab)using the vector recycling rule:
<lang rsplus>x <- paste0(rep("", 100), c("", "", "Fizz"), c("", "", "", "", "Buzz"))
<syntaxhighlight lang="rsplus">x <- paste0(rep("", 100), c("", "", "Fizz"), c("", "", "", "", "Buzz"))
cat(ifelse(x == "", 1:100, x), sep = "\n")</lang>
cat(ifelse(x == "", 1:100, x), sep = "\n")</syntaxhighlight>


Or, for an abuse of the recycling rules that could be generalised:
Or, for an abuse of the recycling rules that could be generalised:
<lang rsplus>x <- paste0(rep("", 100), rep(c("", "Fizz"), times = c(2, 1)), rep(c("", "Buzz"), times = c(4, 1)))
<syntaxhighlight lang="rsplus">x <- paste0(rep("", 100), rep(c("", "Fizz"), times = c(2, 1)), rep(c("", "Buzz"), times = c(4, 1)))
cat(ifelse(x == "", 1:100, x), sep = "\n")</lang>
cat(ifelse(x == "", 1:100, x), sep = "\n")</syntaxhighlight>


Or, with a more straightforward use of ifelse:
Or, with a more straightforward use of ifelse:
<lang rsplus>x <- 1:100
<syntaxhighlight lang="rsplus">x <- 1:100
ifelse(x %% 15 == 0, 'FizzBuzz',
ifelse(x %% 15 == 0, 'FizzBuzz',
ifelse(x %% 5 == 0, 'Buzz',
ifelse(x %% 5 == 0, 'Buzz',
ifelse(x %% 3 == 0, 'Fizz', x)))</lang>
ifelse(x %% 3 == 0, 'Fizz', x)))</syntaxhighlight>
Or, adapting from [https://rosettacode.org/wiki/General_FizzBuzz#Names_solution General FizzBuzz#Names solution]:
Or, adapting from [https://rosettacode.org/wiki/General_FizzBuzz#Names_solution General FizzBuzz#Names solution]:
<lang rsplus>namedNums <- c(Fizz = 3, Buzz = 5)
<syntaxhighlight lang="rsplus">namedNums <- c(Fizz = 3, Buzz = 5)
for(i in 1:100)
for(i in 1:100)
{
{
isFactor <- i %% namedNums == 0
isFactor <- i %% namedNums == 0
print(if(any(isFactor)) paste0(names(namedNums)[isFactor], collapse = "") else i)
print(if(any(isFactor)) paste0(names(namedNums)[isFactor], collapse = "") else i)
}</lang>
}</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket


(for ([n (in-range 1 101)])
(for ([n (in-range 1 101)])
Line 8,402: Line 8,402:
[3 "fizz"]
[3 "fizz"]
[5 "buzz"]
[5 "buzz"]
[_ n])))</lang>
[_ n])))</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
Line 8,408: Line 8,408:
{{works with|Rakudo Star|2015-09-10}}
{{works with|Rakudo Star|2015-09-10}}
Most straightforwardly:
Most straightforwardly:
<lang perl6>for 1 .. 100 {
<syntaxhighlight lang="raku" line>for 1 .. 100 {
when $_ %% (3 & 5) { say 'FizzBuzz'; }
when $_ %% (3 & 5) { say 'FizzBuzz'; }
when $_ %% 3 { say 'Fizz'; }
when $_ %% 3 { say 'Fizz'; }
when $_ %% 5 { say 'Buzz'; }
when $_ %% 5 { say 'Buzz'; }
default { .say; }
default { .say; }
}</lang>
}</syntaxhighlight>
Or abusing multi subs:
Or abusing multi subs:
<lang perl6>multi sub fizzbuzz(Int $ where * %% 15) { 'FizzBuzz' }
<syntaxhighlight lang="raku" line>multi sub fizzbuzz(Int $ where * %% 15) { 'FizzBuzz' }
multi sub fizzbuzz(Int $ where * %% 5) { 'Buzz' }
multi sub fizzbuzz(Int $ where * %% 5) { 'Buzz' }
multi sub fizzbuzz(Int $ where * %% 3) { 'Fizz' }
multi sub fizzbuzz(Int $ where * %% 3) { 'Fizz' }
multi sub fizzbuzz(Int $number ) { $number }
multi sub fizzbuzz(Int $number ) { $number }
(1 .. 100)».&fizzbuzz.say;</lang>
(1 .. 100)».&fizzbuzz.say;</syntaxhighlight>
Or abusing list metaoperators:
Or abusing list metaoperators:
<lang perl6>[1..100].map({[~] ($_%%3, $_%%5) »||» "" Z&& <fizz buzz> or $_ })».say</lang>
<syntaxhighlight lang="raku" line>[1..100].map({[~] ($_%%3, $_%%5) »||» "" Z&& <fizz buzz> or $_ })».say</syntaxhighlight>
Concisely (readable):
Concisely (readable):
<lang perl6>say 'Fizz' x $_ %% 3 ~ 'Buzz' x $_ %% 5 || $_ for 1 .. 100;</lang>
<syntaxhighlight lang="raku" line>say 'Fizz' x $_ %% 3 ~ 'Buzz' x $_ %% 5 || $_ for 1 .. 100;</syntaxhighlight>
Shortest FizzBuzz to date:
Shortest FizzBuzz to date:
<lang perl6>say "Fizz"x$_%%3~"Buzz"x$_%%5||$_ for 1..100</lang>
<syntaxhighlight lang="raku" line>say "Fizz"x$_%%3~"Buzz"x$_%%5||$_ for 1..100</syntaxhighlight>
And here's an implementation that never checks for divisibility:
And here's an implementation that never checks for divisibility:
<lang perl6>.say for
<syntaxhighlight lang="raku" line>.say for
(
(
(flat ('' xx 2, 'Fizz') xx *)
(flat ('' xx 2, 'Fizz') xx *)
Line 8,434: Line 8,434:
)
)
Z||
Z||
1 .. 100;</lang>
1 .. 100;</syntaxhighlight>


=={{header|RapidQ}}==
=={{header|RapidQ}}==
The [[#BASIC|BASIC]] solutions work with RapidQ, too.
The [[#BASIC|BASIC]] solutions work with RapidQ, too.
However, here is a bit more esoteric solution using the IIF() function.
However, here is a bit more esoteric solution using the IIF() function.
<lang rapidq>FOR i=1 TO 100
<syntaxhighlight lang="rapidq">FOR i=1 TO 100
t$ = IIF(i MOD 3 = 0, "Fizz", "") + IIF(i MOD 5 = 0, "Buzz", "")
t$ = IIF(i MOD 3 = 0, "Fizz", "") + IIF(i MOD 5 = 0, "Buzz", "")
PRINT IIF(LEN(t$), t$, i)
PRINT IIF(LEN(t$), t$, i)
NEXT i</lang>
NEXT i</syntaxhighlight>


=={{header|Rascal}}==
=={{header|Rascal}}==
<lang rascal>import IO;
<syntaxhighlight lang="rascal">import IO;


public void fizzbuzz() {
public void fizzbuzz() {
Line 8,452: Line 8,452:
println((fb == "") ?"<n>" : fb);
println((fb == "") ?"<n>" : fb);
}
}
}</lang>
}</syntaxhighlight>


=={{header|Raven}}==
=={{header|Raven}}==
<lang raven>100 each 1 + as n
<syntaxhighlight lang="raven">100 each 1 + as n
''
''
n 3 mod 0 = if 'Fizz' cat
n 3 mod 0 = if 'Fizz' cat
n 5 mod 0 = if 'Buzz' cat
n 5 mod 0 = if 'Buzz' cat
dup empty if drop n
dup empty if drop n
say</lang>
say</syntaxhighlight>


=={{header|REALbasic}}==
=={{header|REALbasic}}==
Line 8,466: Line 8,466:


=={{header|ReasonML}}==
=={{header|ReasonML}}==
<lang ocaml>
<syntaxhighlight lang="ocaml">
let fizzbuzz i =>
let fizzbuzz i =>
switch (i mod 3, i mod 5) {
switch (i mod 3, i mod 5) {
Line 8,478: Line 8,478:
print_endline (fizzbuzz i)
print_endline (fizzbuzz i)
};
};
</syntaxhighlight>
</lang>


=={{header|REBOL}}==
=={{header|REBOL}}==
An implementation that concatenates strings and includes a proper code header (title, date, etc.)
An implementation that concatenates strings and includes a proper code header (title, date, etc.)
<lang REBOL>REBOL [
<syntaxhighlight lang="rebol">REBOL [
Title: "FizzBuzz"
Title: "FizzBuzz"
URL: http://rosettacode.org/wiki/FizzBuzz
URL: http://rosettacode.org/wiki/FizzBuzz
Line 8,499: Line 8,499:
]
]
print x
print x
]</lang>
]</syntaxhighlight>
Here is an example by Nick Antonaccio.
Here is an example by Nick Antonaccio.
<lang REBOL>repeat i 100 [
<syntaxhighlight lang="rebol">repeat i 100 [
print switch/default 0 compose [
print switch/default 0 compose [
(mod i 15) ["fizzbuzz"]
(mod i 15) ["fizzbuzz"]
Line 8,507: Line 8,507:
(mod i 5) ["buzz"]
(mod i 5) ["buzz"]
][i]
][i]
]</lang>
]</syntaxhighlight>


And a minimized version:
And a minimized version:
<lang REBOL>repeat i 100[j:""if i // 3 = 0[j:"fizz"]if i // 5 = 0[j: join j"buzz"]if""= j[j: i]print j]</lang>
<syntaxhighlight lang="rebol">repeat i 100[j:""if i // 3 = 0[j:"fizz"]if i // 5 = 0[j: join j"buzz"]if""= j[j: i]print j]</syntaxhighlight>


The following is presented as a curiosity only, not as an example of good coding practice:
The following is presented as a curiosity only, not as an example of good coding practice:
<lang REBOL>m: func [i d] [0 = mod i d]
<syntaxhighlight lang="rebol">m: func [i d] [0 = mod i d]
spick: func [t x y][either any [not t "" = t][y][x]]
spick: func [t x y][either any [not t "" = t][y][x]]
zz: func [i] [rejoin [spick m i 3 "Fizz" "" spick m i 5 "Buzz" ""]]
zz: func [i] [rejoin [spick m i 3 "Fizz" "" spick m i 5 "Buzz" ""]]
repeat i 100 [print spick z: zz i z i]</lang>
repeat i 100 [print spick z: zz i z i]</syntaxhighlight>


=={{header|Red}}==
=={{header|Red}}==
<lang rebol>Red ["FizzBuzz"]
<syntaxhighlight lang="rebol">Red ["FizzBuzz"]


repeat i 100 [
repeat i 100 [
Line 8,528: Line 8,528:
true [i]
true [i]
]
]
]</lang>
]</syntaxhighlight>


=={{header|Retro}}==
=={{header|Retro}}==
This is a port of some [http://weblog.raganwald.com/2007/01/dont-overthink-fizzbuzz.html Forth code].
This is a port of some [http://weblog.raganwald.com/2007/01/dont-overthink-fizzbuzz.html Forth code].
<lang Retro>: fizz? ( s-f ) 3 mod 0 = ;
<syntaxhighlight lang="retro">: fizz? ( s-f ) 3 mod 0 = ;
: buzz? ( s-f ) 5 mod 0 = ;
: buzz? ( s-f ) 5 mod 0 = ;
: num? ( s-f ) dup fizz? swap buzz? or 0 = ;
: num? ( s-f ) dup fizz? swap buzz? or 0 = ;
Line 8,539: Line 8,539:
: ?num ( s- ) num? &putn &drop if ;
: ?num ( s- ) num? &putn &drop if ;
: fizzbuzz ( s- ) dup ?fizz dup ?buzz dup ?num space ;
: fizzbuzz ( s- ) dup ?fizz dup ?buzz dup ?num space ;
: all ( - ) 100 [ 1+ fizzbuzz ] iter ;</lang>
: all ( - ) 100 [ 1+ fizzbuzz ] iter ;</syntaxhighlight>
It's cleaner to use quotes and combinators though:
It's cleaner to use quotes and combinators though:
<lang Retro>needs math'
<syntaxhighlight lang="retro">needs math'
: <fizzbuzz>
: <fizzbuzz>
[ 15 ^math'divisor? ] [ drop "FizzBuzz" puts ] when
[ 15 ^math'divisor? ] [ drop "FizzBuzz" puts ] when
[ 3 ^math'divisor? ] [ drop "Fizz" puts ] when
[ 3 ^math'divisor? ] [ drop "Fizz" puts ] when
[ 5 ^math'divisor? ] [ drop "Buzz" puts ] when putn ;
[ 5 ^math'divisor? ] [ drop "Buzz" puts ] when putn ;
: fizzbuzz cr 100 [ 1+ <fizzbuzz> space ] iter ;</lang>
: fizzbuzz cr 100 [ 1+ <fizzbuzz> space ] iter ;</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
Line 8,552: Line 8,552:
This version's program logic closely mirrors the problem statement:
This version's program logic closely mirrors the problem statement:
===three IF-THEN===
===three IF-THEN===
<lang rexx>/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
<syntaxhighlight lang="rexx">/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
/*╔═══════════════════════════════════╗*/
/*╔═══════════════════════════════════╗*/
do j=1 to 100; z= j /*║ ║*/
do j=1 to 100; z= j /*║ ║*/
Line 8,559: Line 8,559:
if j//(3*5)==0 then z= 'FizzBuzz' /*║ ║*/
if j//(3*5)==0 then z= 'FizzBuzz' /*║ ║*/
say right(z, 8) /*╚═══════════════════════════════════╝*/
say right(z, 8) /*╚═══════════════════════════════════╝*/
end /*j*/ /*stick a fork in it, we're all done. */</lang>
end /*j*/ /*stick a fork in it, we're all done. */</syntaxhighlight>
'''output'''
'''output'''
<pre style="height:40ex">
<pre style="height:40ex">
Line 8,667: Line 8,667:
This version is a different form, but essentially identical to the &nbsp; '''IF-THEN''' &nbsp; (above),
This version is a different form, but essentially identical to the &nbsp; '''IF-THEN''' &nbsp; (above),
<br>but doesn't require the use of a temporary variable to hold/contain the output.
<br>but doesn't require the use of a temporary variable to hold/contain the output.
<lang rexx>/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
<syntaxhighlight lang="rexx">/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
/*╔═══════════════════════════════════╗*/
/*╔═══════════════════════════════════╗*/
do j=1 to 100 /*║ ║*/
do j=1 to 100 /*║ ║*/
Line 8,676: Line 8,676:
otherwise say right(j, 8) /*╚═══════════════════════════════════╝*/
otherwise say right(j, 8) /*╚═══════════════════════════════════╝*/
end /*select*/
end /*select*/
end /*j*/ /*stick a fork in it, we're all done. */</lang>
end /*j*/ /*stick a fork in it, we're all done. */</syntaxhighlight>
'''output''' &nbsp; is identical to the 1<sup>st</sup> REXX version.
'''output''' &nbsp; is identical to the 1<sup>st</sup> REXX version.


===two IF-THEN===
===two IF-THEN===
This version lends itself to expansion &nbsp; (such as using &nbsp; '''Jazz''' &nbsp; for multiples of &nbsp; '''7''').
This version lends itself to expansion &nbsp; (such as using &nbsp; '''Jazz''' &nbsp; for multiples of &nbsp; '''7''').
<lang rexx>/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
<syntaxhighlight lang="rexx">/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/


do j=1 for 100; _=
do j=1 for 100; _=
Line 8,688: Line 8,688:
/* if j//7 ==0 then _=_'Jazz' */ /* ◄─── note that this is a comment. */
/* if j//7 ==0 then _=_'Jazz' */ /* ◄─── note that this is a comment. */
say right(word(_ j,1),8)
say right(word(_ j,1),8)
end /*j*/ /*stick a fork in it, we're all done. */</lang>
end /*j*/ /*stick a fork in it, we're all done. */</syntaxhighlight>
'''output''' &nbsp; is identical to the 1<sup>st</sup> REXX version.
'''output''' &nbsp; is identical to the 1<sup>st</sup> REXX version.


==="geek" version===
==="geek" version===
<lang rexx>/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
<syntaxhighlight lang="rexx">/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
/* [↓] concise, but somewhat obtuse. */
/* [↓] concise, but somewhat obtuse. */
do j=1 for 100
do j=1 for 100
say right(word(word('Fizz', 1+(j//3\==0))word('Buzz', 1+(j//5\==0)) j, 1), 8)
say right(word(word('Fizz', 1+(j//3\==0))word('Buzz', 1+(j//5\==0)) j, 1), 8)
end /*j*/
end /*j*/
/*stick a fork in it, we're all done. */</lang>
/*stick a fork in it, we're all done. */</syntaxhighlight>
'''output''' &nbsp; is identical to the 1<sup>st</sup> REXX version. <br><br>
'''output''' &nbsp; is identical to the 1<sup>st</sup> REXX version. <br><br>


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
for n = 1 to 100
for n = 1 to 100
if n % 15 = 0 see "" + n + " = " + "FizzBuzz"+ nl
if n % 15 = 0 see "" + n + " = " + "FizzBuzz"+ nl
Line 8,708: Line 8,708:
else see "" + n + " = " + n + nl ok
else see "" + n + " = " + n + nl ok
next
next
</syntaxhighlight>
</lang>


=={{header|Robotic}}==
=={{header|Robotic}}==
<lang robotic>
<syntaxhighlight lang="robotic">
set "local1" to 1
set "local1" to 1
: "loop"
: "loop"
Line 8,738: Line 8,738:
: "done"
: "done"
end
end
</syntaxhighlight>
</lang>


The '''wait for 10''' function is not really necessary, but it helps to slow down the output.
The '''wait for 10''' function is not really necessary, but it helps to slow down the output.
Line 8,772: Line 8,772:


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>1.upto(100) do |n|
<syntaxhighlight lang="ruby">1.upto(100) do |n|
print "Fizz" if a = (n % 3).zero?
print "Fizz" if a = (n % 3).zero?
print "Buzz" if b = (n % 5).zero?
print "Buzz" if b = (n % 5).zero?
print n unless (a || b)
print n unless (a || b)
puts
puts
end</lang>
end</syntaxhighlight>
A bit more straightforward:
A bit more straightforward:
<lang ruby>(1..100).each do |n|
<syntaxhighlight lang="ruby">(1..100).each do |n|
puts if (n % 15).zero?
puts if (n % 15).zero?
"FizzBuzz"
"FizzBuzz"
Line 8,789: Line 8,789:
n
n
end
end
end</lang>
end</syntaxhighlight>
Enumerable#Lazy and classes:
Enumerable#Lazy and classes:


Line 8,795: Line 8,795:


i.e, grabbing the first 10 fizz numbers starting from 30, fizz = Fizz.new(30,10) #=> [30, 33, 36, 39, 42, 45, 48, 51, 54, 57]
i.e, grabbing the first 10 fizz numbers starting from 30, fizz = Fizz.new(30,10) #=> [30, 33, 36, 39, 42, 45, 48, 51, 54, 57]
<lang ruby>
<syntaxhighlight lang="ruby">
class Enumerator::Lazy
class Enumerator::Lazy
def filter_map
def filter_map
Line 8,887: Line 8,887:
min(2,b) if b < f and b < fb
min(2,b) if b < f and b < fb
min(0,fb) if fb < b and fb < f
min(0,fb) if fb < b and fb < f
end</lang>
end</syntaxhighlight>


An example using string interpolation:
An example using string interpolation:
<lang ruby>(1..100).each do |n|
<syntaxhighlight lang="ruby">(1..100).each do |n|
v = "#{"Fizz" if n % 3 == 0}#{"Buzz" if n % 5 == 0}"
v = "#{"Fizz" if n % 3 == 0}#{"Buzz" if n % 5 == 0}"
puts v.empty? ? n : v
puts v.empty? ? n : v
end</lang>
end</syntaxhighlight>


Interpolation inspired one-liner:
Interpolation inspired one-liner:
<lang ruby>1.upto(100) { |n| puts "#{'Fizz' if n % 3 == 0}#{'Buzz' if n % 5 == 0}#{n if n % 3 != 0 && n % 5 != 0}" }</lang>
<syntaxhighlight lang="ruby">1.upto(100) { |n| puts "#{'Fizz' if n % 3 == 0}#{'Buzz' if n % 5 == 0}#{n if n % 3 != 0 && n % 5 != 0}" }</syntaxhighlight>


An example using append:
An example using append:
<lang ruby>1.upto 100 do |n|
<syntaxhighlight lang="ruby">1.upto 100 do |n|
r = ''
r = ''
r << 'Fizz' if n % 3 == 0
r << 'Fizz' if n % 3 == 0
Line 8,905: Line 8,905:
r << n.to_s if r.empty?
r << n.to_s if r.empty?
puts r
puts r
end</lang>
end</syntaxhighlight>


Yet another solution:
Yet another solution:
<lang>1.upto(100) { |i| puts "#{[:Fizz][i%3]}#{[:Buzz][i%5]}"[/.+/] || i }</lang>
<syntaxhighlight lang="text">1.upto(100) { |i| puts "#{[:Fizz][i%3]}#{[:Buzz][i%5]}"[/.+/] || i }</syntaxhighlight>


Yet another solution:
Yet another solution:
<lang ruby>1.upto(100){|i|puts'FizzBuzz '[n=i**4%-15,n+13]||i}</lang>
<syntaxhighlight lang="ruby">1.upto(100){|i|puts'FizzBuzz '[n=i**4%-15,n+13]||i}</syntaxhighlight>


Used Enumerable#cycle:
Used Enumerable#cycle:
<lang ruby>f = [nil, nil, :Fizz].cycle
<syntaxhighlight lang="ruby">f = [nil, nil, :Fizz].cycle
b = [nil, nil, nil, nil, :Buzz].cycle
b = [nil, nil, nil, nil, :Buzz].cycle
(1..100).each do |i|
(1..100).each do |i|
puts "#{f.next}#{b.next}"[/.+/] || i
puts "#{f.next}#{b.next}"[/.+/] || i
end</lang>
end</syntaxhighlight>


After beforehand preparing the Array which put the number from 1 to 100, it processes.
After beforehand preparing the Array which put the number from 1 to 100, it processes.
<lang ruby>seq = *0..100
<syntaxhighlight lang="ruby">seq = *0..100
{Fizz:3, Buzz:5, FizzBuzz:15}.each{|k,n| n.step(100,n){|i|seq[i]=k}}
{Fizz:3, Buzz:5, FizzBuzz:15}.each{|k,n| n.step(100,n){|i|seq[i]=k}}
puts seq.drop(1)</lang>
puts seq.drop(1)</syntaxhighlight>


Monkeypatch example:
Monkeypatch example:
<lang ruby>class Integer
<syntaxhighlight lang="ruby">class Integer
def fizzbuzz
def fizzbuzz
v = "#{"Fizz" if self % 3 == 0}#{"Buzz" if self % 5 == 0}"
v = "#{"Fizz" if self % 3 == 0}#{"Buzz" if self % 5 == 0}"
Line 8,933: Line 8,933:
end
end


puts *(1..100).map(&:fizzbuzz)</lang>
puts *(1..100).map(&:fizzbuzz)</syntaxhighlight>


Without mutable variables or inline printing.
Without mutable variables or inline printing.
<lang ruby>fizzbuzz = ->(i) do
<syntaxhighlight lang="ruby">fizzbuzz = ->(i) do
(i%15).zero? and next "FizzBuzz"
(i%15).zero? and next "FizzBuzz"
(i%3).zero? and next "Fizz"
(i%3).zero? and next "Fizz"
Line 8,943: Line 8,943:
end
end


puts (1..100).map(&fizzbuzz).join("\n")</lang>
puts (1..100).map(&fizzbuzz).join("\n")</syntaxhighlight>
[[Jump anywhere#Ruby]] has a worse example of FizzBuzz, using a continuation!
[[Jump anywhere#Ruby]] has a worse example of FizzBuzz, using a continuation!


Using Ruby 3's Pattern Matching:
Using Ruby 3's Pattern Matching:
<lang ruby>
<syntaxhighlight lang="ruby">
1.upto(100) do |n|
1.upto(100) do |n|
puts case [(n % 3).zero?, (n % 5).zero?]
puts case [(n % 3).zero?, (n % 5).zero?]
Line 8,960: Line 8,960:
end
end
end
end
</syntaxhighlight>
</lang>


=={{header|Ruby with RSpec}}==
=={{header|Ruby with RSpec}}==
Line 8,968: Line 8,968:
Your spec/fizzbuzz_spec.rb file should like this:
Your spec/fizzbuzz_spec.rb file should like this:


<lang ruby>
<syntaxhighlight lang="ruby">
require 'fizzbuzz'
require 'fizzbuzz'


Line 9,009: Line 9,009:
end
end
end
end
</lang>
</syntaxhighlight>


There are many ways to get these tests to pass. Here is an example solution of what your lib/fizzbuzz.rb file could look like:
There are many ways to get these tests to pass. Here is an example solution of what your lib/fizzbuzz.rb file could look like:


<lang ruby>
<syntaxhighlight lang="ruby">
def fizzbuzz(number)
def fizzbuzz(number)
return 'FizzBuzz' if is_divisible_by_fifteen?(number)
return 'FizzBuzz' if is_divisible_by_fifteen?(number)
Line 9,037: Line 9,037:
end
end


</syntaxhighlight>
</lang>


When writing Test Driven code, it's important to remember that you should use the Red, Green, Refactor cycle. Simply writing each of these code snippets independently would go against everything TDD is about. Here is a good video that takes you through the process of writing this [https://www.youtube.com/watch?v=CHTep2zQVAc&feature=youtu.be FizzBuzz implementation using Ruby & RSpec].
When writing Test Driven code, it's important to remember that you should use the Red, Green, Refactor cycle. Simply writing each of these code snippets independently would go against everything TDD is about. Here is a good video that takes you through the process of writing this [https://www.youtube.com/watch?v=CHTep2zQVAc&feature=youtu.be FizzBuzz implementation using Ruby & RSpec].
Line 9,047: Line 9,047:


Basic example with a for loop and match:
Basic example with a for loop and match:
<lang rust>fn main() {
<syntaxhighlight lang="rust">fn main() {
for i in 1..=100 {
for i in 1..=100 {
match (i % 3, i % 5) {
match (i % 3, i % 5) {
Line 9,056: Line 9,056:
}
}
}
}
}</lang>
}</syntaxhighlight>


Using an iterator and immutable data:
Using an iterator and immutable data:


<lang rust>use std::borrow::Cow;
<syntaxhighlight lang="rust">use std::borrow::Cow;


fn main() {
fn main() {
Line 9,072: Line 9,072:
.for_each(|n| println!("{:?}", n));
.for_each(|n| println!("{:?}", n));
}
}
</syntaxhighlight>
</lang>


A folding iterator version, buffered with a single string allocation, by making use of expressions the <code>write!</code> macro.
A folding iterator version, buffered with a single string allocation, by making use of expressions the <code>write!</code> macro.


<lang rust>use std::fmt::Write;
<syntaxhighlight lang="rust">use std::fmt::Write;


fn fizzbuzz() -> String {
fn fizzbuzz() -> String {
Line 9,093: Line 9,093:
fn main() {
fn main() {
println!("{}", fizzbuzz());
println!("{}", fizzbuzz());
}</lang>
}</syntaxhighlight>


Or the ultimate optimized version with hardcoded output, no standard library or main function, and direct assembly syscalls to write to stdout.
Or the ultimate optimized version with hardcoded output, no standard library or main function, and direct assembly syscalls to write to stdout.
<lang rust>#![no_std]
<syntaxhighlight lang="rust">#![no_std]
#![feature(asm, lang_items, libc, no_std, start)]
#![feature(asm, lang_items, libc, no_std, start)]
Line 9,132: Line 9,132:
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] extern fn panic_fmt() {}</lang>
#[lang = "panic_fmt"] extern fn panic_fmt() {}</syntaxhighlight>


=={{header|Salmon}}==
=={{header|Salmon}}==
<lang Salmon>iterate (x; [1...100])
<syntaxhighlight lang="salmon">iterate (x; [1...100])
((x % 15 == 0) ? "FizzBuzz" :
((x % 15 == 0) ? "FizzBuzz" :
((x % 3 == 0) ? "Fizz" :
((x % 3 == 0) ? "Fizz" :
((x % 5 == 0) ? "Buzz" : x)))!;</lang>
((x % 5 == 0) ? "Buzz" : x)))!;</syntaxhighlight>
or
or
<lang Salmon>iterate (x; [1...100])
<syntaxhighlight lang="salmon">iterate (x; [1...100])
{
{
if (x % 15 == 0)
if (x % 15 == 0)
Line 9,150: Line 9,150:
else
else
x!;
x!;
};</lang>
};</syntaxhighlight>


=={{header|SAS}}==
=={{header|SAS}}==
<lang SAS>data _null_;
<syntaxhighlight lang="sas">data _null_;
do i=1 to 100;
do i=1 to 100;
if mod(i,15)=0 then put "FizzBuzz";
if mod(i,15)=0 then put "FizzBuzz";
Line 9,160: Line 9,160:
else put i;
else put i;
end;
end;
run;</lang>
run;</syntaxhighlight>


=={{header|Sather}}==
=={{header|Sather}}==
<lang sather>class MAIN is
<syntaxhighlight lang="sather">class MAIN is
main is
main is
loop i ::= 1.upto!(100);
loop i ::= 1.upto!(100);
Line 9,176: Line 9,176:
end;
end;
end;
end;
end;</lang>
end;</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
Line 9,182: Line 9,182:


===Idiomatic scala code===
===Idiomatic scala code===
<lang scala>object FizzBuzz extends App {
<syntaxhighlight lang="scala">object FizzBuzz extends App {
1 to 100 foreach { n =>
1 to 100 foreach { n =>
println((n % 3, n % 5) match {
println((n % 3, n % 5) match {
Line 9,191: Line 9,191:
})
})
}
}
}</lang>
}</syntaxhighlight>


===Geeky over-generalized solution ☺===
===Geeky over-generalized solution ☺===
<lang scala>def replaceMultiples(x: Int, rs: (Int, String)*): Either[Int, String] =
<syntaxhighlight lang="scala">def replaceMultiples(x: Int, rs: (Int, String)*): Either[Int, String] =
rs map { case (n, s) => Either cond(x % n == 0, s, x)} reduceLeft ((a, b) =>
rs map { case (n, s) => Either cond(x % n == 0, s, x)} reduceLeft ((a, b) =>
a fold(_ => b, s => b fold(_ => a, t => Right(s + t))))
a fold(_ => b, s => b fold(_ => a, t => Right(s + t))))
Line 9,200: Line 9,200:
def fizzbuzz = replaceMultiples(_: Int, 3 -> "Fizz", 5 -> "Buzz") fold(_.toString, identity)
def fizzbuzz = replaceMultiples(_: Int, 3 -> "Fizz", 5 -> "Buzz") fold(_.toString, identity)


1 to 100 map fizzbuzz foreach println</lang>
1 to 100 map fizzbuzz foreach println</syntaxhighlight>


===By a two-liners geek===
===By a two-liners geek===
<lang scala>def f(n: Int, div: Int, met: String, notMet: String): String = if (n % div == 0) met else notMet
<syntaxhighlight lang="scala">def f(n: Int, div: Int, met: String, notMet: String): String = if (n % div == 0) met else notMet
for (i <- 1 to 100) println(f(i, 15, "FizzBuzz", f(i, 3, "Fizz", f(i, 5, "Buzz", i.toString))))</lang>
for (i <- 1 to 100) println(f(i, 15, "FizzBuzz", f(i, 3, "Fizz", f(i, 5, "Buzz", i.toString))))</syntaxhighlight>


===One-liner geek===
===One-liner geek===
<lang scala>for (i <- 1 to 100) println(Seq(15 -> "FizzBuzz", 3 -> "Fizz", 5 -> "Buzz").find(i % _._1 == 0).map(_._2).getOrElse(i))</lang>
<syntaxhighlight lang="scala">for (i <- 1 to 100) println(Seq(15 -> "FizzBuzz", 3 -> "Fizz", 5 -> "Buzz").find(i % _._1 == 0).map(_._2).getOrElse(i))</syntaxhighlight>


===Functional Scala===
===Functional Scala===
<lang scala>def fizzBuzzTerm(n: Int): String =
<syntaxhighlight lang="scala">def fizzBuzzTerm(n: Int): String =
if (n % 15 == 0) "FizzBuzz"
if (n % 15 == 0) "FizzBuzz"
else if (n % 3 == 0) "Fizz"
else if (n % 3 == 0) "Fizz"
Line 9,216: Line 9,216:
else n.toString
else n.toString


def fizzBuzz(): Unit = LazyList.from(1).take(100).map(fizzBuzzTerm).foreach(println)</lang>
def fizzBuzz(): Unit = LazyList.from(1).take(100).map(fizzBuzzTerm).foreach(println)</syntaxhighlight>


===Scala 3 (Dotty)===
===Scala 3 (Dotty)===
Written so as to introduce changes, with comments.
Written so as to introduce changes, with comments.
<lang scala>def fizzBuzzTerm(n: Int): String | Int = // union types
<syntaxhighlight lang="scala">def fizzBuzzTerm(n: Int): String | Int = // union types
(n % 3, n % 5) match // optional semantic indentation; no braces
(n % 3, n % 5) match // optional semantic indentation; no braces
case (0, 0) => "FizzBuzz"
case (0, 0) => "FizzBuzz"
Line 9,233: Line 9,233:


@main def run(): Unit = // @main for main method; can take custom args
@main def run(): Unit = // @main for main method; can take custom args
fizzBuzz.take(100).foreach(println)</lang>
fizzBuzz.take(100).foreach(println)</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
<lang scheme>(do ((i 1 (+ i 1)))
<syntaxhighlight lang="scheme">(do ((i 1 (+ i 1)))
((> i 100))
((> i 100))
(display
(display
Line 9,243: Line 9,243:
((= 0 (modulo i 5)) "Buzz")
((= 0 (modulo i 5)) "Buzz")
(else i)))
(else i)))
(newline))</lang>
(newline))</syntaxhighlight>




Using a recursive procedure.
Using a recursive procedure.
<lang scheme>(define (fizzbuzz x y)
<syntaxhighlight lang="scheme">(define (fizzbuzz x y)
(println
(println
(cond (( = (modulo x 15) 0 ) "FizzBuzz")
(cond (( = (modulo x 15) 0 ) "FizzBuzz")
Line 9,256: Line 9,256:
(if (< x y) (fizzbuzz (+ x 1) y)))
(if (< x y) (fizzbuzz (+ x 1) y)))


(fizzbuzz 1 100)</lang>
(fizzbuzz 1 100)</syntaxhighlight>


Approach with maps and filters, easier to change, less readable
Approach with maps and filters, easier to change, less readable
than the previous.
than the previous.
<lang scheme>(define (fizzbuzz x)
<syntaxhighlight lang="scheme">(define (fizzbuzz x)
(let ([words '((3 . "Fizz")
(let ([words '((3 . "Fizz")
(5 . "Buzz"))])
(5 . "Buzz"))])
Line 9,269: Line 9,269:


(fizzbuzz 15)
(fizzbuzz 15)
</syntaxhighlight>
</lang>


=={{header|Sed}}==
=={{header|Sed}}==
<lang sed>#n
<syntaxhighlight lang="sed">#n
# doesn't work if there's no input
# doesn't work if there's no input
# initialize counters (0 = empty) and value
# initialize counters (0 = empty) and value
Line 9,311: Line 9,311:
# loop until value = 100
# loop until value = 100
/100/q
/100/q
b loop</lang>
b loop</syntaxhighlight>


Using <tt>seq</tt>:
Using <tt>seq</tt>:
<lang sed>
<syntaxhighlight lang="sed">
seq 100 | sed '/.*[05]$/s//Buzz/;n;s//Buzz/;n;s//Buzz/;s/^[0-9]*/Fizz/'
seq 100 | sed '/.*[05]$/s//Buzz/;n;s//Buzz/;n;s//Buzz/;s/^[0-9]*/Fizz/'
</syntaxhighlight>
</lang>


=== GNU sed ===
=== GNU sed ===
Line 9,323: Line 9,323:
Using <tt>seq</tt>:
Using <tt>seq</tt>:


<lang sed>
<syntaxhighlight lang="sed">
seq 100 | sed '0~3 s/.*/Fizz/; 0~5 s/[0-9]*$/Buzz/'
seq 100 | sed '0~3 s/.*/Fizz/; 0~5 s/[0-9]*$/Buzz/'
</syntaxhighlight>
</lang>


Using <tt>yes</tt>:
Using <tt>yes</tt>:
<lang sed>
<syntaxhighlight lang="sed">
yes | sed -n '0~3s/y/Fizz/;0~5s/y*$/Buzz/;tx;=;b;:x;p;100q'
yes | sed -n '0~3s/y/Fizz/;0~5s/y*$/Buzz/;tx;=;b;:x;p;100q'
</syntaxhighlight>
</lang>


Using the option ''-z (--zero-data)'' first introduced in GNU sed 4.2.2 (2012-12-22):
Using the option ''-z (--zero-data)'' first introduced in GNU sed 4.2.2 (2012-12-22):
<lang sed>
<syntaxhighlight lang="sed">
sed -nz '0~3s/^/Fizz/;0~5s/$/Buzz/;tx;=;b;:x;p;100q' /dev/zero | sed 'y/\c@/\n/'
sed -nz '0~3s/^/Fizz/;0~5s/$/Buzz/;tx;=;b;:x;p;100q' /dev/zero | sed 'y/\c@/\n/'
</syntaxhighlight>
</lang>
Second invocation of ''sed'' translates null characters to newlines. The same could be achieved with <tt>tr \\0 \\n</tt>
Second invocation of ''sed'' translates null characters to newlines. The same could be achieved with <tt>tr \\0 \\n</tt>


=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";


const proc: main is func
const proc: main is func
Line 9,356: Line 9,356:
end if;
end if;
end for;
end for;
end func;</lang>
end func;</syntaxhighlight>


=={{header|SenseTalk}}==
=={{header|SenseTalk}}==
<lang sensetalk>repeat 100
<syntaxhighlight lang="sensetalk">repeat 100
put "" into output
put "" into output
if the counter is a multiple of 3 then
if the counter is a multiple of 3 then
Line 9,371: Line 9,371:
end if
end if
put output
put output
end repeat</lang>
end repeat</syntaxhighlight>


=={{header|SequenceL}}==
=={{header|SequenceL}}==


<lang sequencel>import <Utilities/Conversion.sl>;
<syntaxhighlight lang="sequencel">import <Utilities/Conversion.sl>;
import <Utilities/Sequence.sl>;
import <Utilities/Sequence.sl>;


Line 9,390: Line 9,390:
foreach i within 1 ... 100;
foreach i within 1 ... 100;
in
in
delimit(result, '\n');</lang>
delimit(result, '\n');</syntaxhighlight>


=={{header|Shale}}==
=={{header|Shale}}==


<lang Shale>#!/usr/local/bin/shale
<syntaxhighlight lang="shale">#!/usr/local/bin/shale


string library
string library
Line 9,407: Line 9,407:
r "" equals string::() { i } { r } if i "%3d: %p\n" printf
r "" equals string::() { i } { r } if i "%3d: %p\n" printf
i++
i++
} while</lang>
} while</syntaxhighlight>


=={{header|Shen}}==
=={{header|Shen}}==
<lang Shen>(define fizzbuzz
<syntaxhighlight lang="shen">(define fizzbuzz
101 -> (nl)
101 -> (nl)
N -> (let divisible-by? (/. A B (integer? (/ A B)))
N -> (let divisible-by? (/. A B (integer? (/ A B)))
Line 9,423: Line 9,423:
(fizzbuzz (+ N 1))))))
(fizzbuzz (+ N 1))))))


(fizzbuzz 1)</lang>
(fizzbuzz 1)</syntaxhighlight>


=== Alternative showing off other features like prolog integration and guards ===
=== Alternative showing off other features like prolog integration and guards ===
<lang Shen>(defprolog fizz
<syntaxhighlight lang="shen">(defprolog fizz
0 <-- (is _ (output "Fizz"));
0 <-- (is _ (output "Fizz"));
N <-- (when (> N 0)) (is N1 (- N 3)) (fizz N1);
N <-- (when (> N 0)) (is N1 (- N 3)) (fizz N1);
Line 9,455: Line 9,455:


(fizzbuzz 1 100)
(fizzbuzz 1 100)
</syntaxhighlight>
</lang>


=={{header|Sidef}}==
=={{header|Sidef}}==
Structured:
Structured:
<lang ruby>{ |i|
<syntaxhighlight lang="ruby">{ |i|
if (i %% 3) {
if (i %% 3) {
print "Fizz"
print "Fizz"
Line 9,467: Line 9,467:
elsif (i %% 5) { say "Buzz" }
elsif (i %% 5) { say "Buzz" }
else { say i }
else { say i }
} * 100</lang>
} * 100</syntaxhighlight>


Declarative:
Declarative:
<lang ruby>func fizzbuzz({ _ %% 15 }) { "FizzBuzz" }
<syntaxhighlight lang="ruby">func fizzbuzz({ _ %% 15 }) { "FizzBuzz" }
func fizzbuzz({ _ %% 5 }) { "Buzz" }
func fizzbuzz({ _ %% 5 }) { "Buzz" }
func fizzbuzz({ _ %% 3 }) { "Fizz" }
func fizzbuzz({ _ %% 3 }) { "Fizz" }
func fizzbuzz( n ) { n }
func fizzbuzz( n ) { n }


for n in (1..100) { say fizzbuzz(n) }</lang>
for n in (1..100) { say fizzbuzz(n) }</syntaxhighlight>


One-liner:
One-liner:
<lang ruby>{|i|say "#{<Fizz>[i%3]}#{<Buzz>[i%5]}"||i}*100</lang>
<syntaxhighlight lang="ruby">{|i|say "#{<Fizz>[i%3]}#{<Buzz>[i%5]}"||i}*100</syntaxhighlight>


=={{header|Simula}}==
=={{header|Simula}}==
<lang simula>begin
<syntaxhighlight lang="simula">begin
integer i;
integer i;
for i := 1 step 1 until 100 do
for i := 1 step 1 until 100 do
Line 9,495: Line 9,495:
outimage
outimage
end;
end;
end</lang>
end</syntaxhighlight>


=={{header|SkookumScript}}==
=={{header|SkookumScript}}==
Answer by printing out one of the 4 alternatives:
Answer by printing out one of the 4 alternatives:
<lang javascript>
<syntaxhighlight lang="javascript">
1.to 100
1.to 100
[
[
Line 9,508: Line 9,508:
else [idx])
else [idx])
]
]
</syntaxhighlight>
</lang>


Answer by building up a string:
Answer by building up a string:
<lang javascript>
<syntaxhighlight lang="javascript">
1.to 100
1.to 100
[
[
Line 9,519: Line 9,519:
println(if str.empty? [idx] else [str])
println(if str.empty? [idx] else [str])
]
]
</syntaxhighlight>
</lang>
Or doing initial bind in one step:
Or doing initial bind in one step:
<lang javascript>
<syntaxhighlight lang="javascript">
1.to 100
1.to 100
[
[
Line 9,529: Line 9,529:
println(if str.empty? [idx] else [str])
println(if str.empty? [idx] else [str])
]
]
</syntaxhighlight>
</lang>


=={{header|Slate}}==
=={{header|Slate}}==
<lang slate>n@(Integer traits) fizzbuzz
<syntaxhighlight lang="slate">n@(Integer traits) fizzbuzz
[
[
output ::= ((n \\ 3) isZero ifTrue: ['Fizz'] ifFalse: ['']) ; ((n \\ 5) isZero ifTrue: ['Buzz'] ifFalse: ['']).
output ::= ((n \\ 3) isZero ifTrue: ['Fizz'] ifFalse: ['']) ; ((n \\ 5) isZero ifTrue: ['Buzz'] ifFalse: ['']).
output isEmpty ifTrue: [n printString] ifFalse: [output]
output isEmpty ifTrue: [n printString] ifFalse: [output]
].
].
1 to: 100 do: [| :i | inform: i fizzbuzz]</lang>
1 to: 100 do: [| :i | inform: i fizzbuzz]</syntaxhighlight>


=={{header|Small}}==
=={{header|Small}}==
Line 9,544: Line 9,544:
=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
Since only GNU Smalltalk supports file-based programming, we'll be using its syntax.
Since only GNU Smalltalk supports file-based programming, we'll be using its syntax.
<lang smalltalk>Integer extend [
<syntaxhighlight lang="smalltalk">Integer extend [
fizzbuzz [
fizzbuzz [
| fb |
| fb |
Line 9,552: Line 9,552:
]
]
]
]
1 to: 100 do: [ :i | i fizzbuzz displayNl ]</lang>
1 to: 100 do: [ :i | i fizzbuzz displayNl ]</syntaxhighlight>
A Squeak/Pharo example using the Transcript window:
A Squeak/Pharo example using the Transcript window:
<lang smalltalk>(1 to: 100) do:
<syntaxhighlight lang="smalltalk">(1 to: 100) do:
[:n |
[:n |
((n \\ 3)*(n \\ 5)) isZero
((n \\ 3)*(n \\ 5)) isZero
Line 9,562: Line 9,562:
(n \\ 5) isZero
(n \\ 5) isZero
ifTrue: [Transcript show: 'Buzz'].
ifTrue: [Transcript show: 'Buzz'].
Transcript cr.]</lang>
Transcript cr.]</syntaxhighlight>
The Squeak/Pharo examples below present possibilities using the powerful classes available. In this example, the dictionary can have as keys pairs of booleans and in the interaction the several boolean patterns select the string to be printed or if the pattern is not found the number itself is printed.
The Squeak/Pharo examples below present possibilities using the powerful classes available. In this example, the dictionary can have as keys pairs of booleans and in the interaction the several boolean patterns select the string to be printed or if the pattern is not found the number itself is printed.
<lang smalltalk>fizzbuzz := Dictionary with: #(true true)->'FizzBuzz'
<syntaxhighlight lang="smalltalk">fizzbuzz := Dictionary with: #(true true)->'FizzBuzz'
with: #(true false)->'Fizz'
with: #(true false)->'Fizz'
with: #(false true)->'Buzz'.
with: #(false true)->'Buzz'.
Line 9,571: Line 9,571:
[ :i | Transcript show:
[ :i | Transcript show:
(fizzbuzz at: {i isDivisibleBy: 3. i isDivisibleBy: 5}
(fizzbuzz at: {i isDivisibleBy: 3. i isDivisibleBy: 5}
ifAbsent: [ i ]); cr]</lang>
ifAbsent: [ i ]); cr]</syntaxhighlight>
Smalltalk does not have a case-select construct, but a similar effect can be attained using a collection and the #includes: method:
Smalltalk does not have a case-select construct, but a similar effect can be attained using a collection and the #includes: method:
<lang smalltalk>1 to: 100 do: [:n | |r|
<syntaxhighlight lang="smalltalk">1 to: 100 do: [:n | |r|
r := n rem: 15.
r := n rem: 15.
Transcript show: (r isZero
Transcript show: (r isZero
Line 9,582: Line 9,582:
ifTrue:['buzz']
ifTrue:['buzz']
ifFalse:[n]]]);
ifFalse:[n]]]);
cr].</lang>
cr].</syntaxhighlight>
If the construction of the whole collection is done beforehand, Smalltalk provides a straightforward way of doing because collections can be heterogeneous (may contain any object):
If the construction of the whole collection is done beforehand, Smalltalk provides a straightforward way of doing because collections can be heterogeneous (may contain any object):
<lang smalltalk>fbz := (1 to: 100) asOrderedCollection.
<syntaxhighlight lang="smalltalk">fbz := (1 to: 100) asOrderedCollection.
3 to: 100 by: 3 do: [:i | fbz at: i put: 'Fizz'].
3 to: 100 by: 3 do: [:i | fbz at: i put: 'Fizz'].
5 to: 100 by: 5 do: [:i | fbz at: i put: 'Buzz'].
5 to: 100 by: 5 do: [:i | fbz at: i put: 'Buzz'].
15 to: 100 by: 15 do: [:i | fbz at: i put: 'FizzBuzz'].
15 to: 100 by: 15 do: [:i | fbz at: i put: 'FizzBuzz'].
fbz do: [:i | Transcript show: i; cr].</lang>
fbz do: [:i | Transcript show: i; cr].</syntaxhighlight>
The approach building a dynamic string can be done as well:
The approach building a dynamic string can be done as well:
<lang smalltalk>1 to: 100 do: [:i | |fb s|
<syntaxhighlight lang="smalltalk">1 to: 100 do: [:i | |fb s|
fb := {i isDivisibleBy: 3. i isDivisibleBy: 5. nil}.
fb := {i isDivisibleBy: 3. i isDivisibleBy: 5. nil}.
fb at: 3 put: (fb first | fb second) not.
fb at: 3 put: (fb first | fb second) not.
s := '<1?Fizz:><2?Buzz:><3?{1}:>' format: {i printString}.
s := '<1?Fizz:><2?Buzz:><3?{1}:>' format: {i printString}.
Transcript show: (s expandMacrosWithArguments: fb); cr].</lang>
Transcript show: (s expandMacrosWithArguments: fb); cr].</syntaxhighlight>


=={{header|SNOBOL4}}==
=={{header|SNOBOL4}}==
Merely posting a solution by Daniel Lyons
Merely posting a solution by Daniel Lyons
<lang snobol4> I = 1
<syntaxhighlight lang="snobol4"> I = 1
LOOP FIZZBUZZ = ""
LOOP FIZZBUZZ = ""
EQ(REMDR(I, 3), 0) :F(TRY_5)
EQ(REMDR(I, 3), 0) :F(TRY_5)
Line 9,609: Line 9,609:
I = I + 1
I = I + 1
LE(I, 100) :S(LOOP)
LE(I, 100) :S(LOOP)
END</lang>
END</syntaxhighlight>


=={{header|SNUSP}}==
=={{header|SNUSP}}==
Line 9,617: Line 9,617:
{{libheader|SQL}}
{{libheader|SQL}}
===Oracle SQL===
===Oracle SQL===
<lang sql>SELECT CASE
<syntaxhighlight lang="sql">SELECT CASE
WHEN MOD(level,15)=0 THEN 'FizzBuzz'
WHEN MOD(level,15)=0 THEN 'FizzBuzz'
WHEN MOD(level,3)=0 THEN 'Fizz'
WHEN MOD(level,3)=0 THEN 'Fizz'
Line 9,624: Line 9,624:
END FizzBuzz
END FizzBuzz
FROM dual
FROM dual
CONNECT BY LEVEL <= 100;</lang>
CONNECT BY LEVEL <= 100;</syntaxhighlight>
Or using Oracle's DECODE and NVL:
Or using Oracle's DECODE and NVL:
<lang sql>SELECT nvl(decode(MOD(level,3),0,'Fizz')||decode(MOD(level,5),0,'Buzz'),level)
<syntaxhighlight lang="sql">SELECT nvl(decode(MOD(level,3),0,'Fizz')||decode(MOD(level,5),0,'Buzz'),level)
FROM dual
FROM dual
CONNECT BY level<=100;</lang>
CONNECT BY level<=100;</syntaxhighlight>


===PostgreSQL specific===
===PostgreSQL specific===
<lang sql>SELECT i, fizzbuzz
<syntaxhighlight lang="sql">SELECT i, fizzbuzz
FROM
FROM
(SELECT i,
(SELECT i,
Line 9,641: Line 9,641:
END AS fizzbuzz
END AS fizzbuzz
FROM generate_series(1,100) AS i) AS fb
FROM generate_series(1,100) AS i) AS fb
WHERE fizzbuzz IS NOT NULL;</lang>
WHERE fizzbuzz IS NOT NULL;</syntaxhighlight>


Using Generate_Series and tables only:
Using Generate_Series and tables only:
<lang sql>SELECT COALESCE(FIZZ || BUZZ, FIZZ, BUZZ, OUTPUT) AS FIZZBUZZ FROM
<syntaxhighlight lang="sql">SELECT COALESCE(FIZZ || BUZZ, FIZZ, BUZZ, OUTPUT) AS FIZZBUZZ FROM
(SELECT GENERATE_SERIES AS FULL_SERIES, TO_CHAR(GENERATE_SERIES,'99') AS OUTPUT
(SELECT GENERATE_SERIES AS FULL_SERIES, TO_CHAR(GENERATE_SERIES,'99') AS OUTPUT
FROM GENERATE_SERIES(1,100)) F LEFT JOIN
FROM GENERATE_SERIES(1,100)) F LEFT JOIN
Line 9,650: Line 9,650:
FIZZ.FIZZ_SERIES = F.FULL_SERIES LEFT JOIN
FIZZ.FIZZ_SERIES = F.FULL_SERIES LEFT JOIN
(SELECT TEXT 'Buzz' AS BUZZ, GENERATE_SERIES AS BUZZ_SERIES FROM GENERATE_SERIES(0,100,5)) BUZZ ON
(SELECT TEXT 'Buzz' AS BUZZ, GENERATE_SERIES AS BUZZ_SERIES FROM GENERATE_SERIES(0,100,5)) BUZZ ON
BUZZ.BUZZ_SERIES = F.FULL_SERIES;</lang>
BUZZ.BUZZ_SERIES = F.FULL_SERIES;</syntaxhighlight>


===Recursive Common Table Expressions (MSSQL 2005+)===
===Recursive Common Table Expressions (MSSQL 2005+)===
<lang sql>WITH nums (n, fizzbuzz ) AS (
<syntaxhighlight lang="sql">WITH nums (n, fizzbuzz ) AS (
SELECT 1, CONVERT(nvarchar, 1) UNION ALL
SELECT 1, CONVERT(nvarchar, 1) UNION ALL
SELECT
SELECT
Line 9,667: Line 9,667:
SELECT n, fizzbuzz FROM nums
SELECT n, fizzbuzz FROM nums
ORDER BY n ASC
ORDER BY n ASC
OPTION ( MAXRECURSION 100 )</lang>
OPTION ( MAXRECURSION 100 )</syntaxhighlight>
===Generic SQL using a join===
===Generic SQL using a join===
This should work in most RDBMSs, but you may need to change <tt>MOD(i,divisor)</tt> to <tt>i % divisor</tt>.
This should work in most RDBMSs, but you may need to change <tt>MOD(i,divisor)</tt> to <tt>i % divisor</tt>.
<lang SQL>-- Load some numbers
<syntaxhighlight lang="sql">-- Load some numbers
CREATE TABLE numbers(i INTEGER);
CREATE TABLE numbers(i INTEGER);
INSERT INTO numbers VALUES(1);
INSERT INTO numbers VALUES(1);
Line 9,693: Line 9,693:
-- Tidy up
-- Tidy up
DROP TABLE fizzbuzz;
DROP TABLE fizzbuzz;
DROP TABLE numbers;</lang>
DROP TABLE numbers;</syntaxhighlight>


=={{header|Squirrel}}==
=={{header|Squirrel}}==
<lang javascript>function Fizzbuzz(n) {
<syntaxhighlight lang="javascript">function Fizzbuzz(n) {
for (local i = 1; i <= n; i += 1) {
for (local i = 1; i <= n; i += 1) {
if (i % 15 == 0)
if (i % 15 == 0)
Line 9,709: Line 9,709:
}
}
}
}
Fizzbuzz(100);</lang>
Fizzbuzz(100);</syntaxhighlight>


=={{header|Stata}}==
=={{header|Stata}}==
<lang stata>program define fizzbuzz
<syntaxhighlight lang="stata">program define fizzbuzz
args n
args n
forvalues i = 1/`n' {
forvalues i = 1/`n' {
Line 9,728: Line 9,728:
}
}
}
}
end</lang>
end</syntaxhighlight>


=={{header|Swahili}}==
=={{header|Swahili}}==
<lang swahili>
<syntaxhighlight lang="swahili">
shughuli fizzBuzz() {
shughuli fizzBuzz() {
kwa i = 1 mpaka 100 {
kwa i = 1 mpaka 100 {
Line 9,745: Line 9,745:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|Swift}}==
=={{header|Swift}}==
=== using a switch statement ===
=== using a switch statement ===
<lang swift>for i in 1...100 {
<syntaxhighlight lang="swift">for i in 1...100 {
switch (i % 3, i % 5) {
switch (i % 3, i % 5) {
case (0, 0):
case (0, 0):
Line 9,760: Line 9,760:
print(i)
print(i)
}
}
}</lang>
}</syntaxhighlight>
=== using two if statements and an Optional ===
=== using two if statements and an Optional ===
<lang swift>for i in 1...100{
<syntaxhighlight lang="swift">for i in 1...100{
var s:String?
var s:String?
if i%3==0{s="Fizz"}
if i%3==0{s="Fizz"}
if i%5==0{s=(s ?? "")+"Buzz"}
if i%5==0{s=(s ?? "")+"Buzz"}
print(s ?? i)
print(s ?? i)
}</lang>
}</syntaxhighlight>


=={{header|Symsyn}}==
=={{header|Symsyn}}==
<lang symsyn>
<syntaxhighlight lang="symsyn">
| FizzBuzz
| FizzBuzz


Line 9,793: Line 9,793:
goif
goif
endif
endif
</syntaxhighlight>
</lang>


=={{header|Tailspin}}==
=={{header|Tailspin}}==
<lang tailspin>
<syntaxhighlight lang="tailspin">
templates fizz
templates fizz
$ mod 3 -> #
$ mod 3 -> #
Line 9,809: Line 9,809:
[ 1..100 -> '$->fizz;$->buzz;' ] -> \[i](when <=''> do $i ! otherwise $ !\)... -> '$;
[ 1..100 -> '$->fizz;$->buzz;' ] -> \[i](when <=''> do $i ! otherwise $ !\)... -> '$;
' -> !OUT::write
' -> !OUT::write
</syntaxhighlight>
</lang>


=={{header|Tcl}}==
=={{header|Tcl}}==
<lang tcl>proc fizzbuzz {n {m1 3} {m2 5}} {
<syntaxhighlight lang="tcl">proc fizzbuzz {n {m1 3} {m2 5}} {
for {set i 1} {$i <= $n} {incr i} {
for {set i 1} {$i <= $n} {incr i} {
set ans ""
set ans ""
Line 9,820: Line 9,820:
}
}
}
}
fizzbuzz 100</lang>
fizzbuzz 100</syntaxhighlight>
The following example shows Tcl's substitution mechanism that allows to concatenate the results of two successive commands into a string:
The following example shows Tcl's substitution mechanism that allows to concatenate the results of two successive commands into a string:
<lang tcl>while {[incr i] < 101} {
<syntaxhighlight lang="tcl">while {[incr i] < 101} {
set fb [if {$i % 3 == 0} {list Fizz}][if {$i % 5 == 0} {list Buzz}]
set fb [if {$i % 3 == 0} {list Fizz}][if {$i % 5 == 0} {list Buzz}]
if {$fb ne ""} {puts $fb} {puts $i}
if {$fb ne ""} {puts $fb} {puts $i}
}</lang>
}</syntaxhighlight>
This version uses list rotation, so avoiding an explicit mod operation:
This version uses list rotation, so avoiding an explicit mod operation:
<lang tcl>set f [lrepeat 5 "Fizz" {$i} {$i}]
<syntaxhighlight lang="tcl">set f [lrepeat 5 "Fizz" {$i} {$i}]
foreach i {5 10} {lset f $i "Buzz"};lset f 0 "FizzBuzz"
foreach i {5 10} {lset f $i "Buzz"};lset f 0 "FizzBuzz"
for {set i 1} {$i <= 100} {incr i} {
for {set i 1} {$i <= 100} {incr i} {
puts [subst [lindex [set f [list {*}[lassign $f ff] $ff]] 0]]
puts [subst [lindex [set f [list {*}[lassign $f ff] $ff]] 0]]
}</lang>
}</syntaxhighlight>


=={{header|TI-83 BASIC}}==
=={{header|TI-83 BASIC}}==
Line 9,840: Line 9,840:


=={{header|TransFORTH}}==
=={{header|TransFORTH}}==
<lang forth>: FIZZBUZZ
<syntaxhighlight lang="forth">: FIZZBUZZ
101 1 DO
101 1 DO
I 15 MOD 0 = IF
I 15 MOD 0 = IF
Line 9,849: Line 9,849:
PRINT " BUZZ "
PRINT " BUZZ "
ELSE I . THEN THEN THEN
ELSE I . THEN THEN THEN
CR LOOP ;</lang>
CR LOOP ;</syntaxhighlight>


=={{header|True BASIC}}==
=={{header|True BASIC}}==
Line 9,855: Line 9,855:


=={{header|Turing}}==
=={{header|Turing}}==
<lang Turing>for i : 1 .. 100
<syntaxhighlight lang="turing">for i : 1 .. 100
if i mod 15 = 0 then
if i mod 15 = 0 then
put "Fizzbuzz"
put "Fizzbuzz"
Line 9,865: Line 9,865:
put i
put i
end if
end if
end for</lang>
end for</syntaxhighlight>


=={{header|TUSCRIPT}}==
=={{header|TUSCRIPT}}==
<lang tuscript>$$ MODE TUSCRIPT
<syntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
LOOP n=1,100
LOOP n=1,100
mod=MOD (n,15)
mod=MOD (n,15)
Line 9,881: Line 9,881:
PRINT n
PRINT n
ENDSELECT
ENDSELECT
ENDLOOP</lang>
ENDLOOP</syntaxhighlight>


=={{header|TXR}}==
=={{header|TXR}}==
<lang shell>$ txr -p "(mapcar (op if @1 @1 @2) (repeat '(nil nil fizz nil buzz fizz nil nil fizz buzz nil fizz nil nil fizzbuzz)) (range 1 100))"</lang>
<syntaxhighlight lang="shell">$ txr -p "(mapcar (op if @1 @1 @2) (repeat '(nil nil fizz nil buzz fizz nil nil fizz buzz nil fizz nil nil fizzbuzz)) (range 1 100))"</syntaxhighlight>


=={{header|UNIX Shell}}==
=={{header|UNIX Shell}}==
This solution should work with any Bourne-compatible shell: <!-- http://ideone.com/usJXGo -->
This solution should work with any Bourne-compatible shell: <!-- http://ideone.com/usJXGo -->
<lang bash>i=1
<syntaxhighlight lang="bash">i=1
while expr $i '<=' 100 >/dev/null; do
while expr $i '<=' 100 >/dev/null; do
w=false
w=false
Line 9,895: Line 9,895:
if $w; then echo; else echo $i; fi
if $w; then echo; else echo $i; fi
i=`expr $i + 1`
i=`expr $i + 1`
done</lang>
done</syntaxhighlight>


===Versions for specific shells===
===Versions for specific shells===
Line 9,903: Line 9,903:
and it should work with every POSIX shell.
and it should work with every POSIX shell.
<!-- http://ideone.com/5yZmOz -->
<!-- http://ideone.com/5yZmOz -->
<lang bash>n=1
<syntaxhighlight lang="bash">n=1
while [ 100 -ge n ]; do
while [ 100 -ge n ]; do
if [ $((n % 15)) -eq 0 ]; then
if [ $((n % 15)) -eq 0 ]; then
Line 9,915: Line 9,915:
fi
fi
n=$((n + 1))
n=$((n + 1))
done</lang>
done</syntaxhighlight>


The next solution requires the <code>(( ))</code> command from the [[Korn Shell]].
The next solution requires the <code>(( ))</code> command from the [[Korn Shell]].
{{works with|pdksh|5.2.14}}
{{works with|pdksh|5.2.14}}
<lang bash>NUM=1
<syntaxhighlight lang="bash">NUM=1
until ((NUM == 101)) ; do
until ((NUM == 101)) ; do
if ((NUM % 15 == 0)) ; then
if ((NUM % 15 == 0)) ; then
Line 9,931: Line 9,931:
fi
fi
((NUM = NUM + 1))
((NUM = NUM + 1))
done</lang>
done</syntaxhighlight>


A version using concatenation:
A version using concatenation:
{{works with|bash|3}}
{{works with|bash|3}}
<lang bash>for ((n=1; n<=100; n++))
<syntaxhighlight lang="bash">for ((n=1; n<=100; n++))
do
do
fb=''
fb=''
Line 9,941: Line 9,941:
[ $(( n % 5 )) -eq 0 ] && fb="${fb}Buzz"
[ $(( n % 5 )) -eq 0 ] && fb="${fb}Buzz"
[ -n "${fb}" ] && echo "${fb}" || echo "$n"
[ -n "${fb}" ] && echo "${fb}" || echo "$n"
done</lang>
done</syntaxhighlight>


A version using some of the insane overkill of Bash 4:
A version using some of the insane overkill of Bash 4:
{{works with|bash|4}}
{{works with|bash|4}}
<lang bash>command_not_found_handle () {
<syntaxhighlight lang="bash">command_not_found_handle () {
local Fizz=3 Buzz=5
local Fizz=3 Buzz=5
[ $(( $2 % $1 )) -eq 0 ] && echo -n $1 && [ ${!1} -eq 3 ]
[ $(( $2 % $1 )) -eq 0 ] && echo -n $1 && [ ${!1} -eq 3 ]
Line 9,954: Line 9,954:
Fizz $i && ! Buzz $i || echo -n $i
Fizz $i && ! Buzz $i || echo -n $i
echo
echo
done</lang>
done</syntaxhighlight>


Bash one-liner: <!-- http://ideone.com/xMEGFK -->
Bash one-liner: <!-- http://ideone.com/xMEGFK -->
<lang bash>for i in {1..100};do ((($i%15==0))&& echo FizzBuzz)||((($i%5==0))&& echo Buzz;)||((($i%3==0))&& echo Fizz;)||echo $i;done</lang>
<syntaxhighlight lang="bash">for i in {1..100};do ((($i%15==0))&& echo FizzBuzz)||((($i%5==0))&& echo Buzz;)||((($i%3==0))&& echo Fizz;)||echo $i;done</syntaxhighlight>


==={{header|C Shell}}===
==={{header|C Shell}}===
<lang csh>@ n = 1
<syntaxhighlight lang="csh">@ n = 1
while ( $n <= 100 )
while ( $n <= 100 )
if ($n % 15 == 0) then
if ($n % 15 == 0) then
Line 9,972: Line 9,972:
endif
endif
@ n += 1
@ n += 1
end</lang>
end</syntaxhighlight>


=={{header|Ursa}}==
=={{header|Ursa}}==
<lang ursa>#
<syntaxhighlight lang="ursa">#
# fizzbuzz
# fizzbuzz
#
#
Line 9,990: Line 9,990:
end if
end if
out endl console
out endl console
end for</lang>
end for</syntaxhighlight>


=={{header|Ursala}}==
=={{header|Ursala}}==
<lang Ursala>#import std
<syntaxhighlight lang="ursala">#import std
#import nat
#import nat


Line 10,000: Line 10,000:
#show+
#show+


main = fizzbuzz*t iota 101</lang>
main = fizzbuzz*t iota 101</syntaxhighlight>


=={{header|V}}==
=={{header|V}}==
<lang v>[fizzbuzz
<syntaxhighlight lang="v">[fizzbuzz
1 [>=] [
1 [>=] [
[[15 % zero?] ['fizzbuzz' puts]
[[15 % zero?] ['fizzbuzz' puts]
Line 10,011: Line 10,011:
] when succ
] when succ
] while].
] while].
|100 fizzbuzz</lang>
|100 fizzbuzz</syntaxhighlight>


===Second try===
===Second try===
Line 10,017: Line 10,017:


define a command that will generate a sequence
define a command that will generate a sequence
<lang v>[seq [] swap dup [zero? not] [rolldown [dup] dip cons rollup pred] while pop pop].</lang>
<syntaxhighlight lang="v">[seq [] swap dup [zero? not] [rolldown [dup] dip cons rollup pred] while pop pop].</syntaxhighlight>
create a quote that will return a quote that returns a quote if its argument is an integer (A HOF)
create a quote that will return a quote that returns a quote if its argument is an integer (A HOF)
<lang v>[check [N X F : [[integer?] [[X % zero?] [N F cons] if] if]] view].</lang>
<syntaxhighlight lang="v">[check [N X F : [[integer?] [[X % zero?] [N F cons] if] if]] view].</syntaxhighlight>
Create a quote that will make sure that the above quote is applied correctly if given (Number Function)
Create a quote that will make sure that the above quote is applied correctly if given (Number Function)
as arguments.
as arguments.
<lang v>[func [[N F] : [dup N F check i] ] view map].</lang>
<syntaxhighlight lang="v">[func [[N F] : [dup N F check i] ] view map].</syntaxhighlight>
And apply it
And apply it
<lang v>100 seq [
<syntaxhighlight lang="v">100 seq [
[15 [pop 'fizzbuzz' puts]]
[15 [pop 'fizzbuzz' puts]]
[5 [pop 'buzz' puts]]
[5 [pop 'buzz' puts]]
[3 [pop 'fizz' puts]]
[3 [pop 'fizz' puts]]
[1 [puts]]] [func dup] step
[1 [puts]]] [func dup] step
[i true] map pop</lang>
[i true] map pop</syntaxhighlight>
the first one is much better :)
the first one is much better :)


=={{header|Vala}}==
=={{header|Vala}}==
<lang vala>int main() {
<syntaxhighlight lang="vala">int main() {
for (int i = 1; i <= 100; i++) {
for (int i = 1; i <= 100; i++) {
if (i % 3 == 0) stdout.printf("Fizz\n");
if (i % 3 == 0) stdout.printf("Fizz\n");
Line 10,042: Line 10,042:
}
}
return 0;;
return 0;;
}</lang>
}</syntaxhighlight>


=={{header|VAX Assembly}}==
=={{header|VAX Assembly}}==
<lang VAX Assembly> 00000008 0000 1 len =8
<syntaxhighlight lang="vax assembly"> 00000008 0000 1 len =8
00000008 0000 2 msg: .blkb len ;output buffer
00000008 0000 2 msg: .blkb len ;output buffer
0000000C 0008 3 desc: .blkl 1 ;descriptor lenght field
0000000C 0008 3 desc: .blkl 1 ;descriptor lenght field
Line 10,087: Line 10,087:
9F 52 00000064 8F F3 007C 41 AOBLEQ #100,r2,loop ;limit.rl, index.ml
9F 52 00000064 8F F3 007C 41 AOBLEQ #100,r2,loop ;limit.rl, index.ml
04 0084 42 ret
04 0084 42 ret
0085 43 .end start</lang>
0085 43 .end start</syntaxhighlight>


=={{header|VBA}}==
=={{header|VBA}}==
<syntaxhighlight lang="vb">
<lang vb>
Option Explicit
Option Explicit


Line 10,109: Line 10,109:
Next
Next
Debug.Print Join(Tb, vbCrLf)
Debug.Print Join(Tb, vbCrLf)
End Sub</lang>
End Sub</syntaxhighlight>
As an alternative, testing each number only once:
As an alternative, testing each number only once:
<syntaxhighlight lang="vb">
<lang vb>
Sub FizzBuzz()
Sub FizzBuzz()
Dim i As Integer
Dim i As Integer
Line 10,122: Line 10,122:
Debug.Print Join(T, ", ") & ", Buzz"
Debug.Print Join(T, ", ") & ", Buzz"
End Sub
End Sub
</syntaxhighlight>
</lang>


=={{header|VBScript}}==
=={{header|VBScript}}==
{{works with|Windows Script Host|*}}
{{works with|Windows Script Host|*}}
<lang VBScript>For i = 1 To 100
<syntaxhighlight lang="vbscript">For i = 1 To 100
If i Mod 15 = 0 Then
If i Mod 15 = 0 Then
WScript.Echo "FizzBuzz"
WScript.Echo "FizzBuzz"
Line 10,136: Line 10,136:
WScript.Echo i
WScript.Echo i
End If
End If
Next</lang>
Next</syntaxhighlight>


=====An Alternative=====
=====An Alternative=====
{{works with|Windows Script Host|*}}
{{works with|Windows Script Host|*}}
<lang VBScript>With WScript.StdOut
<syntaxhighlight lang="vbscript">With WScript.StdOut
For i = 1 To 100
For i = 1 To 100
If i Mod 3 = 0 Then .Write "Fizz"
If i Mod 3 = 0 Then .Write "Fizz"
Line 10,146: Line 10,146:
If .Column = 1 Then .WriteLine i Else .WriteLine ""
If .Column = 1 Then .WriteLine i Else .WriteLine ""
Next
Next
End With</lang>
End With</syntaxhighlight>


=={{header|Verbexx}}==
=={{header|Verbexx}}==
<lang Verbexx>@LOOP init:{@VAR t3 t5; @VAR i = 1} while:(i <= 100) next:{i++}
<syntaxhighlight lang="verbexx">@LOOP init:{@VAR t3 t5; @VAR i = 1} while:(i <= 100) next:{i++}
{
{
t3 = (i % 3 == 0);
t3 = (i % 3 == 0);
Line 10,159: Line 10,159:
else: { i }
else: { i }
);
);
};</lang>
};</syntaxhighlight>




=={{header|Verilog}}==
=={{header|Verilog}}==
<syntaxhighlight lang="verilog">
<lang Verilog>
module main;
module main;
integer number;
integer number;
Line 10,182: Line 10,182:
end
end
endmodule
endmodule
</syntaxhighlight>
</lang>




=={{header|VHDL}}==
=={{header|VHDL}}==
<lang vhdl>entity fizzbuzz is
<syntaxhighlight lang="vhdl">entity fizzbuzz is
end entity fizzbuzz;
end entity fizzbuzz;


Line 10,214: Line 10,214:
end process p_fizz;
end process p_fizz;


end architecture beh;</lang>
end architecture beh;</syntaxhighlight>


=={{header|Vim Script}}==
=={{header|Vim Script}}==
<lang vim>for i in range(1, 100)
<syntaxhighlight lang="vim">for i in range(1, 100)
if i % 15 == 0
if i % 15 == 0
echo "FizzBuzz"
echo "FizzBuzz"
Line 10,227: Line 10,227:
echo i
echo i
endif
endif
endfor</lang>
endfor</syntaxhighlight>


=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
Line 10,233: Line 10,233:


=={{header|Visual Prolog}}==
=={{header|Visual Prolog}}==
<lang>
<syntaxhighlight lang="text">
implement main
implement main
open core, console
open core, console
Line 10,256: Line 10,256:
goal
goal
console::runUtf8(main::run).
console::runUtf8(main::run).
</syntaxhighlight>
</lang>


=={{header|Vlang}}==
=={{header|Vlang}}==
Updated for Vlang version 0.2.2
Updated for Vlang version 0.2.2
<lang go>const (
<syntaxhighlight lang="go">const (
fizz = Tuple{true, false}
fizz = Tuple{true, false}
buzz = Tuple{false, true}
buzz = Tuple{false, true}
Line 10,289: Line 10,289:
fizzbuzz(15)
fizzbuzz(15)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>1
<pre>1
Line 10,310: Line 10,310:
Basic example with a for loop and match:
Basic example with a for loop and match:


<syntaxhighlight lang="go">
<lang go>
fn main() {
fn main() {
mut i := 1
mut i := 1
Line 10,323: Line 10,323:
}
}
}
}
</syntaxhighlight>
</lang>


Another basic example using the ubiquitous if/else (if) statement:
Another basic example using the ubiquitous if/else (if) statement:


<syntaxhighlight lang="go">
<lang go>
fn main() {
fn main() {
for i in 1..100 {
for i in 1..100 {
Line 10,341: Line 10,341:
}
}
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre style="height:40ex">
<pre style="height:40ex">
Line 10,447: Line 10,447:


=={{header|VTL-2}}==
=={{header|VTL-2}}==
<lang VTL2>10 N=1
<syntaxhighlight lang="vtl2">10 N=1
20 #=30
20 #=30
30 #=N/3*0+%=0*110
30 #=N/3*0+%=0*110
Line 10,461: Line 10,461:
130 ?="Buzz";
130 ?="Buzz";
140 #=!
140 #=!
180 #=70</lang>
180 #=70</syntaxhighlight>


=={{header|Wart}}==
=={{header|Wart}}==
<lang wart>for i 1 (i <= 100) ++i
<syntaxhighlight lang="wart">for i 1 (i <= 100) ++i
prn (if (divides i 15)
prn (if (divides i 15)
"FizzBuzz"
"FizzBuzz"
Line 10,472: Line 10,472:
"Buzz"
"Buzz"
:else
:else
i)</lang>
i)</syntaxhighlight>


=={{header|WDTE}}==
=={{header|WDTE}}==
<lang WDTE>let io => import 'io';
<syntaxhighlight lang="wdte">let io => import 'io';
let s => import 'stream';
let s => import 'stream';


Line 10,487: Line 10,487:
} -- io.writeln io.stdout;
} -- io.writeln io.stdout;


s.range 1 101 -> s.map fizzbuzz -> s.drain;</lang>
s.range 1 101 -> s.map fizzbuzz -> s.drain;</syntaxhighlight>


=={{header|Whitespace}}==
=={{header|Whitespace}}==
Line 10,493: Line 10,493:


=={{header|Wortel}}==
=={{header|Wortel}}==
<lang wortel>@each &x!console.log x !*&x?{%%x 15 "FizzBuzz" %%x 5 "Buzz" %%x 3 "Fizz" x} @to 100</lang>
<syntaxhighlight lang="wortel">@each &x!console.log x !*&x?{%%x 15 "FizzBuzz" %%x 5 "Buzz" %%x 3 "Fizz" x} @to 100</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
<lang ecmascript>for (i in 1..100) {
<syntaxhighlight lang="ecmascript">for (i in 1..100) {
if (i % 15 == 0) {
if (i % 15 == 0) {
System.print("FizzBuzz")
System.print("FizzBuzz")
Line 10,506: Line 10,506:
System.print(i)
System.print(i)
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 10,613: Line 10,613:


=={{header|X86 Assembly}}==
=={{header|X86 Assembly}}==
<lang x86asm>
<syntaxhighlight lang="x86asm">
; x86_64 linux nasm
; x86_64 linux nasm


Line 10,718: Line 10,718:
syscall
syscall
ret
ret
</syntaxhighlight>
</lang>


=={{header|XLISP}}==
=={{header|XLISP}}==
<lang lisp>(defun fizzbuzz ()
<syntaxhighlight lang="lisp">(defun fizzbuzz ()
(defun fizzb (x y)
(defun fizzb (x y)
(display (cond
(display (cond
Line 10,733: Line 10,733:
(fizzb 1 100))
(fizzb 1 100))


(fizzbuzz)</lang>
(fizzbuzz)</syntaxhighlight>


=={{header|XMIDAS}}==
=={{header|XMIDAS}}==
<lang XMIDAS>startmacro
<syntaxhighlight lang="xmidas">startmacro
loop 100 count
loop 100 count
calc/quiet three ^count 3 modulo
calc/quiet three ^count 3 modulo
Line 10,750: Line 10,750:
endif
endif
endloop
endloop
endmacro</lang>
endmacro</syntaxhighlight>


=={{header|Xojo}}==
=={{header|Xojo}}==
<lang vb> For i As Integer = 1 To 100
<syntaxhighlight lang="vb"> For i As Integer = 1 To 100
If i Mod 3 = 0 And i Mod 5 = 0 Then
If i Mod 3 = 0 And i Mod 5 = 0 Then
Print("FizzBuzz")
Print("FizzBuzz")
Line 10,763: Line 10,763:
Print(Str(i))
Print(Str(i))
End If
End If
Next</lang>
Next</syntaxhighlight>
An alternative syntax:
An alternative syntax:
<syntaxhighlight lang="vb">
<lang vb>
For i As Integer = 1 To 100
For i As Integer = 1 To 100
Select Case True
Select Case True
Line 10,777: Line 10,777:
Print(Str(i))
Print(Str(i))
End Select
End Select
Next</lang>
Next</syntaxhighlight>


=={{header|XPath 2.0}}==
=={{header|XPath 2.0}}==
<lang XPath>for $n in 1 to 100 return
<syntaxhighlight lang="xpath">for $n in 1 to 100 return
concat('fizz'[not($n mod 3)], 'buzz'[not($n mod 5)], $n[$n mod 15 = (1,2,4,7,8,11,13,14)])</lang>
concat('fizz'[not($n mod 3)], 'buzz'[not($n mod 5)], $n[$n mod 15 = (1,2,4,7,8,11,13,14)])</syntaxhighlight>
...or alternatively...
...or alternatively...
<lang XPath>for $n in 1 to 100 return
<syntaxhighlight lang="xpath">for $n in 1 to 100 return
($n, 'Fizz', 'Buzz', 'FizzBuzz')[number(($n mod 3) = 0) + number(($n mod 5) = 0)*2 + 1]</lang>
($n, 'Fizz', 'Buzz', 'FizzBuzz')[number(($n mod 3) = 0) + number(($n mod 5) = 0)*2 + 1]</syntaxhighlight>


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>code CrLf=9, IntOut=11, Text=12;
<syntaxhighlight lang="xpl0">code CrLf=9, IntOut=11, Text=12;
int N;
int N;
[for N:= 1 to 100 do
[for N:= 1 to 100 do
Line 10,795: Line 10,795:
CrLf(0);
CrLf(0);
];
];
]</lang>
]</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 10,823: Line 10,823:
===XSLT 1.0===
===XSLT 1.0===
{{works with|xsltproc|libxslt 10126}}
{{works with|xsltproc|libxslt 10126}}
<lang xml><?xml version="1.0" encoding="utf-8" ?>
<syntaxhighlight lang="xml"><?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="utf-8"/>
<xsl:output method="text" encoding="utf-8"/>
Line 10,875: Line 10,875:
<xsl:call-template name="fizzbuzz-range"/>
<xsl:call-template name="fizzbuzz-range"/>
</xsl:template>
</xsl:template>
</xsl:stylesheet></lang>
</xsl:stylesheet></syntaxhighlight>
===XSLT 1.0 With EXSLT===
===XSLT 1.0 With EXSLT===
<lang xml><xsl:stylesheet version="1.0"
<syntaxhighlight lang="xml"><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
xmlns:exsl="http://exslt.org/common"
Line 10,909: Line 10,909:
</xsl:template>
</xsl:template>
</xsl:stylesheet></lang>
</xsl:stylesheet></syntaxhighlight>


===XSLT 2.0===
===XSLT 2.0===
<lang xml><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<syntaxhighlight lang="xml"><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:output method="text"/>


Line 10,921: Line 10,921:
</xsl:template>
</xsl:template>


</xsl:stylesheet></lang>
</xsl:stylesheet></syntaxhighlight>




Line 10,930: Line 10,930:
=={{header|Yorick}}==
=={{header|Yorick}}==
===Iterative solution===
===Iterative solution===
<lang yorick>for(i = 1; i <= 100; i++) {
<syntaxhighlight lang="yorick">for(i = 1; i <= 100; i++) {
if(i % 3 == 0)
if(i % 3 == 0)
write, format="%s", "Fizz";
write, format="%s", "Fizz";
Line 10,938: Line 10,938:
write, format="%d", i;
write, format="%d", i;
write, "";
write, "";
}</lang>
}</syntaxhighlight>
===Vectorized solution===
===Vectorized solution===
<lang yorick>output = swrite(format="%d", indgen(100));
<syntaxhighlight lang="yorick">output = swrite(format="%d", indgen(100));
output(3::3) = "Fizz";
output(3::3) = "Fizz";
output(5::5) = "Buzz";
output(5::5) = "Buzz";
output(15::15) = "FizzBuzz";
output(15::15) = "FizzBuzz";
write, format="%s\n", output;</lang>
write, format="%s\n", output;</syntaxhighlight>


=={{header|Z80 Assembly}}==
=={{header|Z80 Assembly}}==
Line 10,950: Line 10,950:


=={{header|zkl}}==
=={{header|zkl}}==
<lang zkl>foreach n in ([1..100]) {
<syntaxhighlight lang="zkl">foreach n in ([1..100]) {
if(n % 3 == 0) print("Fizz");
if(n % 3 == 0) print("Fizz");
if(not (n%5)) "Buzz".print();
if(not (n%5)) "Buzz".print();
if(n%3 and n%5) print(n);
if(n%3 and n%5) print(n);
println();
println();
}</lang>
}</syntaxhighlight>
Or, using infinite lazy sequences:
Or, using infinite lazy sequences:
<lang zkl>fcn f(a,b,c){ a+b and a+b or c }
<syntaxhighlight lang="zkl">fcn f(a,b,c){ a+b and a+b or c }
Walker.cycle("","","Fizz").zipWith(f,Walker.cycle("","","","","Buzz"),[1..])
Walker.cycle("","","Fizz").zipWith(f,Walker.cycle("","","","","Buzz"),[1..])
.walk(100).concat("\n").println();</lang>
.walk(100).concat("\n").println();</syntaxhighlight>
More of the same:
More of the same:
<lang zkl>Walker.cycle(0,0,"Fizz",0,"Buzz","Fizz",0,0,"Fizz","Buzz",0,"Fizz",0,0,"FizzBuzz")
<syntaxhighlight lang="zkl">Walker.cycle(0,0,"Fizz",0,"Buzz","Fizz",0,0,"Fizz","Buzz",0,"Fizz",0,0,"FizzBuzz")
.zipWith(fcn(a,b){ a or b },[1..]).walk(100).concat("\n").println();</lang>
.zipWith(fcn(a,b){ a or b },[1..]).walk(100).concat("\n").println();</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 10,985: Line 10,985:
=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==
{{trans|Applesoft BASIC}}
{{trans|Applesoft BASIC}}
<lang zxbasic>10 DEF FN m(a,b)=a-INT (a/b)*b
<syntaxhighlight lang="zxbasic">10 DEF FN m(a,b)=a-INT (a/b)*b
20 FOR a=1 TO 100
20 FOR a=1 TO 100
30 LET o$=""
30 LET o$=""
Line 10,992: Line 10,992:
60 IF o$="" THEN LET o$=STR$ a
60 IF o$="" THEN LET o$=STR$ a
70 PRINT o$
70 PRINT o$
80 NEXT a</lang>
80 NEXT a</syntaxhighlight>