FizzBuzz: Difference between revisions

151,197 bytes added ,  1 month ago
No edit summary
(405 intermediate revisions by more than 100 users not shown)
Line 9:
 
But:
:*   for multiples of three,   print   '''Fizz'''     (instead of the number);
:*   for multiples of five,   print   '''Buzz'''     (instead of the number);
:*   for multiples of both three and five,   print   '''FizzBuzz'''     (instead of the number) .
 
 
Line 21:
*   (a blog)   [http://blog.codinghorror.com/fizzbuzz-the-programmers-stairway-to-heaven/ fizzbuzz-the-programmers-stairway-to-heaven]
<br><br>
 
=={{header|11l}}==
{{trans|Python3: Simple}}
 
<syntaxhighlight lang="11l">L(i) 1..100
I i % 15 == 0
print(‘FizzBuzz’)
E I i % 3 == 0
print(‘Fizz’)
E I i % 5 == 0
print(‘Buzz’)
E
print(i)</syntaxhighlight>
 
=={{header|360 Assembly}}==
Line 29 ⟶ 42:
 
=={{header|68000 Assembly}}==
See [[FizzBuzz/Assembly]]
 
=={{header|8080 Assembly}}==
See [[FizzBuzz/Assembly]]
 
Line 35 ⟶ 51:
 
=={{header|8th}}==
<langsyntaxhighlight lang="forth">
with: n
 
Line 61 ⟶ 77:
' fizzbuzz 1 100 loop
cr bye
</syntaxhighlight>
</lang>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program FizzBuzz64.s */
 
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessFizz: .asciz "Fizz\n"
szMessBuzz: .asciz "Buzz\n"
szMessFizzBuzz: .asciz "FizzBuzz\n"
szMessNumber: .asciz "Number : @ "
szCarriageReturn: .asciz "\n"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
sZoneConv: .skip 24
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main: // entry of program
mov x10,3 // divisor 3
mov x11,5 // divisor 5
mov x12,15 // divisor 15
mov x13,1 // indice
1: // loop begin
udiv x14,x13,x12 // multiple 15
msub x15,x14,x12,x13 // remainder
cbnz x15,2f // zero ?
mov x0,x13
ldr x1,qAdrszMessFizzBuzz
bl displayResult
b 4f
2: // multiple 3
udiv x14,x13,x10
msub x15,x14,x10,x13 // remainder
cbnz x15,3f // zero ?
mov x0,x13
ldr x1,qAdrszMessFizz
bl displayResult
b 4f
3: // multiple 5
udiv x14,x13,x11
msub x15,x14,x11,x13 // remainder
cbnz x15,4f // zero ?
mov x0,x13
ldr x1,qAdrszMessBuzz
bl displayResult
4:
add x13,x13,1 // increment indice
cmp x13,100 // maxi ?
ble 1b
 
100: // standard end of the program
mov x8,EXIT // request to exit program
svc 0 // perform the system call
qAdrszMessFizzBuzz: .quad szMessFizzBuzz
qAdrszMessFizz: .quad szMessFizz
qAdrszMessBuzz: .quad szMessBuzz
/******************************************************************/
/* Display résult */
/******************************************************************/
/* x0 contains the number*/
/* x1 contains display string address */
displayResult:
stp x2,lr,[sp,-16]! // save registers
mov x2,x1
ldr x1,qAdrsZoneConv // conversion number
bl conversion10S // decimal conversion
ldr x0,qAdrszMessNumber
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at @ character
bl affichageMess // display message final
mov x0,x2
bl affichageMess
 
ldp x2,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrsZoneConv: .quad sZoneConv
qAdrszMessNumber: .quad szMessNumber
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
 
=={{header|ABAP}}==
===Impure Functional 1===
{{works with|ABAP|7.4 SP05 or Above only}}
<langsyntaxhighlight ABAPlang="abap">DATA: tab TYPE TABLE OF string.
 
tab = VALUE #(
Line 78 ⟶ 193:
 
cl_demo_output=>write( tab ).
cl_demo_output=>display( ).</langsyntaxhighlight>
 
===Impure Functional 2===
{{works with|ABAP|7.4 SP05 or Above only}}
<langsyntaxhighlight ABAPlang="abap">cl_demo_output=>display( VALUEvalue stringtab( FORfor i = 1 WHILEuntil i <=> 100 ( COND #( LET m3 = i MOD 3 m5 = i MOD 5 IN
let fizz = cond #( when i mod WHEN m33 = 0 ANDthen m5|fizz| =else 0space THEN |FIZZBUZZ|)
buzz = cond #( when i mod WHEN m35 = 0 then |buzz| else space THEN |FIZZ|)
fb WHEN m5 = 0|{ fizz }{ buzz }| THEN |BUZZ|in
( switch #( fb when space then i else ELSE ifb ) ) ) ).</langsyntaxhighlight>
 
=={{header|ABC}}==
<syntaxhighlight lang="ABC">HOW TO RETURN fizzbuzz num:
PUT "" IN result
PUT {[3]: "Fizz"; [5]: "Buzz"} IN divwords
FOR div IN keys divwords:
IF num mod div=0:
PUT result^divwords[div] IN result
IF result="":
PUT num>>0 IN result
RETURN result
 
FOR i IN {1..100}:
WRITE fizzbuzz i/</syntaxhighlight>
 
=={{header|ACL2}}==
<langsyntaxhighlight Lisplang="lisp">(defun fizzbuzz-r (i)
(declare (xargs :measure (nfix (- 100 i))))
(prog2$
Line 100 ⟶ 229:
(fizzbuzz-r (1+ i)))))
 
(defun fizzbuzz () (fizzbuzz-r 1))</langsyntaxhighlight>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Main()
BYTE i,d3,d5
 
d3=1 d5=1
FOR i=1 TO 100
DO
IF d3=0 AND d5=0 THEN
Print("FizzBuzz")
ELSEIF d3=0 THEN
Print("Fizz")
ELSEIF d5=0 THEN
Print("Buzz")
ELSE
PrintB(i)
FI
Put(32)
d3==+1 d5==+1
IF d3=3 THEN d3=0 FI
IF d5=5 THEN d5=0 FI
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/FizzBuzz.png Screenshot from Atari 8-bit computer]
<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>
 
=={{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.
<langsyntaxhighlight lang="actionscript">for (var i:int = 1; i <= 100; i++) {
if (i % 15 == 0)
trace('FizzBuzz');
Line 113 ⟶ 275:
else
trace(i);
}</langsyntaxhighlight>
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
procedure Fizzbuzz is
Line 131 ⟶ 293:
end if;
end loop;
end Fizzbuzz;</langsyntaxhighlight>
 
 
=={{header|Agda}}==
<syntaxhighlight lang="agda">
module FizzBuzz where
 
open import Agda.Builtin.IO using (IO)
 
open import Agda.Builtin.Unit renaming (⊤ to Unit)
 
open import Data.Bool using (Bool ; false ; true ; if_then_else_)
 
open import Data.Nat using (ℕ ; zero ; suc ; _≡ᵇ_ ; _%_)
 
open import Data.Nat.Show using (show)
 
open import Data.List using (List ; [] ; _∷_ ; map)
 
open import Data.String using (String ; _++_ ; unlines)
 
postulate putStrLn : String -> IO Unit
{-# FOREIGN GHC import qualified Data.Text as T #-}
{-# COMPILE GHC putStrLn = putStrLn . T.unpack #-}
 
fizz : String
fizz = "Fizz"
 
buzz : String
buzz = "Buzz"
 
_isDivisibleBy_ : (n : ℕ) -> (m : ℕ) -> Bool
n isDivisibleBy zero = false
n isDivisibleBy (suc k) = ((n % (suc k)) ≡ᵇ 0)
 
getTerm : (n : ℕ) -> String
getTerm n =
if (n isDivisibleBy 15) then (fizz ++ buzz)
else if (n isDivisibleBy 3) then fizz
else if (n isDivisibleBy 5) then buzz
else (show n)
 
range : (a : ℕ) -> (b : ℕ) -> List (ℕ)
range k zero = []
range k (suc m) = k ∷ (range (suc k) m)
 
getTerms : (n : ℕ) -> List (String)
getTerms n = map getTerm (range 1 n)
 
fizzBuzz : String
fizzBuzz = unlines (getTerms 100)
 
main : IO Unit
main = putStrLn fizzBuzz
</syntaxhighlight>
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">main:(
FOR i TO 100 DO
printf(($gl$,
Line 148 ⟶ 364:
))
OD
)</langsyntaxhighlight>
or simply:
<langsyntaxhighlight lang="algol68">FOR i TO 100 DO print(((i%*15=0|"FizzBuzz"|:i%*3=0|"Fizz"|:i%*5=0|"Buzz"|i),new line)) OD</langsyntaxhighlight>
 
=={{header|ALGOL-M}}==
<syntaxhighlight lang="algolm">BEGIN
 
INTEGER FUNCTION DIVBY(N, D);
INTEGER N;
INTEGER D;
BEGIN
DIVBY := 1 - (N - D * (N / D));
END;
 
INTEGER I;
FOR I := 1 STEP 1 UNTIL 100 DO
BEGIN
IF DIVBY(I, 15) = 1 THEN
WRITE("FizzBuzz")
ELSE IF DIVBY(I, 5) = 1 THEN
WRITE("Buzz")
ELSE IF DIVBY(I, 3) = 1 THEN
WRITE("Fizz")
ELSE
WRITE(I);
END;
 
END</syntaxhighlight>
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">
begin
i_w := 1; % set integers to print in minimum space %
Line 162 ⟶ 403:
else write( i )
end for_i
end.</langsyntaxhighlight>
 
=={{header|AntLang}}==
<langsyntaxhighlight AntLanglang="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
echo map s</langsyntaxhighlight>
 
=={{header|APEX}}==
<syntaxhighlight lang="apex">
<lang Apex>
for(integer i=1; i <= 100; i++){
String output = '';
Line 181 ⟶ 422:
}
}
</syntaxhighlight>
</lang>
 
=={{header|APL}}==
<langsyntaxhighlight 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]
</syntaxhighlight>
</lang>
 
 
Slightly different approach that makes use of the Decode function (⊥):
<langsyntaxhighlight lang="apl">
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
Line 214 ⟶ 455:
Here's a Dyalog-specific solution taking advantage of its anonymous function extension:
 
<langsyntaxhighlight lang="apl">{ ⍵ 'Fizz' 'Buzz' 'FizzBuzz'[ +/1 2×0=3 5|⍵] }¨1+⍳100</langsyntaxhighlight>
 
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):
 
<syntaxhighlight lang="apl">{(‘FizzBuzz’ ‘Fizz’ ‘Buzz’,⍵)[(0=15 3 5|⍵)⍳1]}¨⍳100</syntaxhighlight>
 
Yet another solution, excessively commented:
 
{{works with|GNU_APL}} (and Dyalog, with [http://course.dyalog.com/autumn2021/Quirks/ ⎕ML ← 2])
 
<syntaxhighlight lang="apl"> ∇ sv ← fizzbuzz n; t;d
[1] ⍝⍝ Solve the popular 'fizzbuzz' problem in APL.
[2] ⍝⍝ \param n - highest number to compute (≥0)
[3] ⍝⍝ \returns sv - a vector of strings representing the fizzbuzz solution for ⍳n
[4] ⍝⍝ (note we return a string vector to avoid a mixed-type result; remove the
[5] ⍝⍝ ⍕ function from the (⍕t[⍵]) term to see the difference).
[6] ⍝⍝⍝⍝
[7] t←⍳n ⍝ the sequence 1..n itself which we'll pick from
[8] ⍝ ... or the words 'fizz', 'buzz', 'fizzbuzz' depending on
[9] ⍝ ... divisibility by 3 and/or 5
[10] ⍝⎕←t ⍝ (Uncomment to see during call)
[11]
[12] d←1+(+⌿ ⊃ {((0=3|⍵)) (2×(0=5|⍵))} ⍳n)
[13] ⍝ || || | | | ↓↓
[14] ⍝ || || | | | ⍳n: generate range (1..n)
[15] ⍝ || || | ↓.....................↓ ↓↓
[16] ⍝ || || | A dfn (lambda) taking its right arg (⍵, ⍳n here) to compute two boolean
[17] ⍝ || || | vectors(v12): divisibility by 3 and 5, respectively, for each of ⍳n
[18] ⍝ || || ↓
[19] ⍝ || || ⊃: Disclose ('lift-up' and pad w/zeros) the 'ragged' matrix of vectors (v12)
[20] ⍝ || || holding divisibility by 3 and 5 of each ⍳n
[21] ⍝ || ↓↓
[22] ⍝ || +⌿: Sum (v12) row-wise to count divisibility (0=neither 3 nor 5, 1=3, 2=3 and 5)
[23] ⍝ ↓↓
[24] ⍝ 1+: Add one to (v12) to make them 1-based for indexing below:
[25] ⍝⎕←d
[26]
[27] sv ← { ((⍕t[⍵]) 'Fizz' 'Buzz' 'FizzBuzz') [d[⍵]]}¨ ⍳n
[28] ⍝ | | | | | |
[29] ⍝ | | | ↓....↓ |
[30] ⍝ | |................................↓ idx |
[31] ⍝ | ( lookup output vector ) |
[32] ⍝ ↓...........................................↓
[33] ⍝ A dfn (lambda) taking as its right arg (⍵) ⍳n and using the 'each' (¨)
[34] ⍝ operator to apply the lambda to each (idx) of ⍳n.
[35]
[36] ⍝⍝ USAGE
[37] ⍝⍝ ⎕ ← ,fizzbuzz 15
[38] ⍝ 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
∇</syntaxhighlight>
 
I prefer the DRYness of solutions that don't have "FizzBuzz" as a separate case; here's such a solution that works with both Dyalog and GNU. You may want to prepend `⍬⊣` to the whole thing in GNU to keep it from returning the list as the value of the expression, causing the interpreter to print it out a second time.
 
{{works with|Dyalog APL}}
{{works with|GNU APL}}
<syntaxhighlight lang="apl">⎕io←1
{⎕←∊'Fizz' 'Buzz'⍵/⍨d,⍱/d←0=3 5|⍵}¨⍳100</syntaxhighlight>
 
Explanation:
<pre>
⎕io←1 Set the index origin to 1; if it were set to 0, the next
step would count from 0 to 99 instead of 1 to 100.
 
{ }¨⍳100 Do the thing in braces for each integer from 1 through 100.
 
3 5|⍵ Make a list of the remainders when the current number is
divided by 3 and 5.
 
d←0= Make it a Boolean vector: true for remainder=0, false
otherwise. Name it d.
 
d,⍱/ Prepend d to the result of reducing itself with XNOR,
yielding a three-element Boolean vector. The first element
is true if the number is divisible by 3; the second if it's
divisible by 5; and the third only if it's divisible by
neither.
 
'Fizz' 'Buzz'⍵/⍨ Use the Boolean vector as a mask to select elements from
a new triple consisting of 'Fizz', 'Buzz', and the current
number. Each of the three elements will be included in the
selection only if the corresponding Boolean is true.
 
∊ Combine the selected elements into one vector/string
 
⎕← And print it out.</pre>
 
=={{header|AppleScript}}==
===Procedural===
<lang AppleScript>property outputText: ""
<syntaxhighlight lang="applescript">property outputText: ""
repeat with i from 1 to 100
if i mod 15 = 0 then
Line 230 ⟶ 556:
set outputText to outputText & linefeed
end repeat
outputText</langsyntaxhighlight>
----
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:
 
<syntaxhighlight lang="applescript">on fizzBuzz(n)
script o
property output : {}
end script
repeat with i from 1 to n
if (i mod 3 = 0) then
if (i mod 15 = 0) then
set end of o's output to "FizzBuzz"
else
set end of o's output to "Fizz"
end if
else if (i mod 5 = 0) then
set end of o's output to "Buzz"
else
set end of o's output to i
end if
end repeat
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set output to o's output as text
set AppleScript's text item delimiters to astid
return output
end fizzBuzz
 
fizzBuzz(100)</syntaxhighlight>
Or, using map(), enumFromTo(), and a more functional pattern of composition:
 
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>-- FIZZBUZZ ------------------------------------------------------------------
 
<syntaxhighlight lang="applescript">on fizzBuzz(n)
script o
property output : {}
end script
repeat with i from 1 to n
set end of o's output to i
end repeat
repeat with x in {{3, "Fizz"}, {5, "Buzz"}, {15, "FizzBuzz"}}
set {m, t} to x
repeat with i from m to n by m
set item i of o's output to t
end repeat
end repeat
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set output to o's output as text
set AppleScript's text item delimiters to astid
return output
end fizzBuzz
 
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.
----
===Functional===
For simplicity, and more efficient use of the scripter's time:
<syntaxhighlight lang="applescript">------------------------- FIZZBUZZ -------------------------
 
-- fizz :: Int -> Bool
Line 260 ⟶ 645:
 
 
-- TEST ------------------------------------------- TEST ---------------------------
on run
Line 269 ⟶ 654:
 
 
-- GENERIC FUNCTIONS ------------------------------------ GENERIC FUNCTIONS ---------------------
 
-- caseOf :: a -> [(predicate, b)] -> Maybe b -> Maybe b
Line 279 ⟶ 664:
return default
end caseOf
 
 
-- enumFromTo :: Int -> Int -> [Int]
Line 293 ⟶ 679:
return lst
end enumFromTo
 
 
-- intercalate :: Text -> [Text] -> Text
Line 301 ⟶ 688:
return strJoined
end intercalate
 
 
-- map :: (a -> b) -> [a] -> [b]
Line 313 ⟶ 701:
end tell
end map
 
 
-- Lift 2nd class handler function into 1st class script wrapper
Line 324 ⟶ 713:
end script
end if
end mReturn</langsyntaxhighlight>
 
=={{header|Applesoft BASIC}}==
Line 330 ⟶ 719:
 
=={{header|Arbre}}==
<langsyntaxhighlight Arbrelang="arbre">fizzbuzz():
for x in [1..100]
if x%5==0 and x%3==0
Line 344 ⟶ 733:
 
main():
fizzbuzz() -> io</langsyntaxhighlight>
 
=={{header|Arc}}==
===Arc 3.1 Base===
<langsyntaxhighlight lang="lisp">(for n 1 100
(prn:if
(multiple n 15) 'FizzBuzz
(multiple n 5) 'Buzz
(multiple n 3) 'Fizz
n))</langsyntaxhighlight>
<langsyntaxhighlight lang="lisp">(for n 1 100
(prn:check (string (when (multiple n 3) 'Fizz)
(when (multiple n 5) 'Buzz))
~empty n)) ; check created string not empty, else return n</langsyntaxhighlight>
 
===Waterhouse Arc===
<langsyntaxhighlight lang="lisp">(for n 1 100
(prn:case (gcd n 15)
1 n
3 'Fizz
5 'Buzz
'FizzBuzz))</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
<syntaxhighlight lang="arm_assembly">
/ * linux GAS */
 
.global _start
 
.data
 
Fizz: .ascii "Fizz\n"
Buzz: .ascii "Buzz\n"
FizzAndBuzz: .ascii "FizzBuzz\n"
 
numstr_buffer: .skip 3
newLine: .ascii "\n"
 
.text
 
_start:
 
bl FizzBuzz
 
mov r7, #1
mov r0, #0
svc #0
 
FizzBuzz:
 
push {lr}
mov r9, #100
 
fizzbuzz_loop:
 
mov r0, r9
mov r1, #15
bl divide
cmp r1, #0
ldreq r1, =FizzAndBuzz
moveq r2, #9
beq fizzbuzz_print
 
mov r0, r9
mov r1, #3
bl divide
cmp r1, #0
ldreq r1, =Fizz
moveq r2, #5
beq fizzbuzz_print
 
mov r0, r9
mov r1, #5
bl divide
cmp r1, #0
ldreq r1, =Buzz
moveq r2, #5
beq fizzbuzz_print
 
mov r0, r9
bl make_num
mov r2, r1
mov r1, r0
 
fizzbuzz_print:
 
mov r0, #1
mov r7, #4
svc #0
 
sub r9, #1
cmp r9, #0
 
bgt fizzbuzz_loop
 
pop {lr}
mov pc, lr
 
make_num:
 
push {lr}
ldr r4, =numstr_buffer
mov r5, #4
mov r6, #1
 
mov r1, #100
bl divide
 
cmp r0, #0
subeq r5, #1
movne r6, #0
 
add r0, #48
strb r0, [r4, #0]
 
mov r0, r1
mov r1, #10
bl divide
 
cmp r0, #0
movne r6, #0
cmp r6, #1
subeq r5, #1
 
add r0, #48
strb r0, [r4, #1]
 
add r1, #48
strb r1, [r4, #2]
 
mov r2, #4
sub r0, r2, r5
add r0, r4, r0
mov r1, r5
 
pop {lr}
mov pc, lr
 
divide:
udiv r2, r0, r1
mul r3, r1, r2
sub r1, r0, r3
mov r0, r2
mov pc, lr
</syntaxhighlight>
 
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">loop 1..100 [x][
case []
when? [0=x%15] -> print "FizzBuzz"
when? [0=x%3] -> print "Fizz"
when? [0=x%5] -> print "Buzz"
else -> print x
]</syntaxhighlight>
{{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>
 
=={{header|AsciiDots}}==
See [[FizzBuzz/EsoLang#AsciiDots]]
 
=={{header|ASIC}}==
See [[FizzBuzz/Basic]]
 
=={{header|Asymptote}}==
<syntaxhighlight lang="asymptote">for(int number = 1; number <= 100; ++number) {
if (number % 15 == 0) {
write("FizzBuzz");
} else {
if (number % 3 == 0) {
write("Fizz");
} else {
if (number % 5 == 0) {
write("Buzz");
} else {
write(number);
}
}
}
}</syntaxhighlight>
 
=={{header|ATS}}==
<langsyntaxhighlight lang="ats">#include "share/atspre_staload.hats"
 
implement main0() = loop(1, 100) where {
Line 385 ⟶ 1,030:
loop(from+1, to)
end
}</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
{{AutoHotkey case}}
<langsyntaxhighlight AutoHotkeylang="autohotkey">Loop, 100
{
If (Mod(A_Index, 15) = 0)
Line 402 ⟶ 1,047:
FileDelete, output.txt
FileAppend, %output%, output.txt
Run, cmd /k type output.txt</langsyntaxhighlight>
A short example with cascading ternary operators and graphical output. Press Esc to close the window.
<langsyntaxhighlight AutoHotkeylang="autohotkey">Gui, Add, Edit, r20
Gui,Show
Loop, 100
Line 410 ⟶ 1,055:
Return
Esc::
ExitApp</langsyntaxhighlight>
 
=={{header|AutoIt}}==
===Example1===
Output via MsgBox():
<langsyntaxhighlight AutoItlang="autoit">For $i = 1 To 100
If Mod($i, 15) = 0 Then
MsgBox(0, "FizzBuzz", "FizzBuzz")
Line 425 ⟶ 1,070:
MsgBox(0, "FizzBuzz", $i)
EndIf
Next</langsyntaxhighlight>
 
===Example2===
Output via console, logfile and/or messagebox:
<langsyntaxhighlight AutoItlang="autoit">#include <Constants.au3>
 
; uncomment how you want to do the output
Line 453 ⟶ 1,098:
EndIf
Next
Out("# Done.")</langsyntaxhighlight>
 
=={{header|Avail}}==
<syntaxhighlight lang="avail">For each i from 1 to 100 do [
Print:
if i mod 15 = 0 then ["FizzBuzz"]
else if i mod 3 = 0 then ["Fizz"]
else if i mod 5 = 0 then ["Buzz"]
else [“i”]
++ "\n";
];</syntaxhighlight>
 
=={{header|AWK}}==
Line 459 ⟶ 1,114:
 
=={{header|Axe}}==
<langsyntaxhighlight lang="axe">For(I,1,100)
!If I^3??I^5
Disp "FIZZBUZZ",i
Line 471 ⟶ 1,126:
.Pause to allow the user to actually read the output
Pause 1000
End</langsyntaxhighlight>
 
=={{header|Babel}}==
<langsyntaxhighlight lang="babel">main:
{ { iter 1 + dup
Line 495 ⟶ 1,150:
"\n" << }
 
100 times }</langsyntaxhighlight>
 
=={{header|BabyCobol}}==
<syntaxhighlight lang="cobol">
* NB: ANY does not exist in BabyCobol so the elegant
* EVALUATE-based COBOL-style solution is impossible here.
* Note the subtly unbalanced IF/ENDs yet valid END at the end.
IDENTIFICATION DIVISION.
PROGRAM-ID. FIZZBUZZ.
DATA DIVISION.
01 INT PICTURE IS 9(3).
01 REM LIKE INT.
01 TMP LIKE INT.
PROCEDURE DIVISION.
LOOP VARYING INT TO 100
DIVIDE 3 INTO INT GIVING TMP REMAINDER REM
IF REM = 0
THEN DISPLAY "Fizz" WITH NO ADVANCING
DIVIDE 5 INTO INT GIVING TMP REMAINDER REM
IF REM = 0
THEN DISPLAY "Buzz" WITH NO ADVANCING
DIVIDE 15 INTO INT GIVING TMP REMAINDER REM
IF REM = 0
THEN DISPLAY ""
ELSE DISPLAY INT
END.
</syntaxhighlight>
 
=={{header|BaCon}}==
Line 502 ⟶ 1,183:
=={{header|bash}}==
Any bash hacker would do this as a one liner at the shell, so...
<langsyntaxhighlight 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</langsyntaxhighlight>
For the sake of readability...
<langsyntaxhighlight 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</langsyntaxhighlight>
Here's a very concise approach, with only 75 characters total.
Unfortunately it relies on aspects of Bash which are rarely used.
<langsyntaxhighlight lang="bash">for i in {1..100};do((i%3))&&x=||x=Fizz;((i%5))||x+=Buzz;echo ${x:-$i};done</langsyntaxhighlight>
Here's the concise approach again, this time separated into multiple lines.
<langsyntaxhighlight 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.
do ((i % 3)) && # If i is not divisible by 3...
Line 522 ⟶ 1,203:
x+=Buzz # ...Otherwise, append (not set) the string "Buzz" to x.
echo ${x:-$i} # Print x unless it is blanked out. Otherwise, print i.
done</langsyntaxhighlight>
It's a bit silly to optimize such a small & fast program,
but for the sake of algorithm analysis it's worth noting that
Line 538 ⟶ 1,219:
 
=={{header|BASIC}}==
See [[FizzBuzz/Basic]]
 
=={{header|Basic09}}==
See [[FizzBuzz/Basic]]
 
=={{header|BASIC256}}==
See [[FizzBuzz/Basic]]
 
Line 543 ⟶ 1,230:
FOR /L version:
 
<langsyntaxhighlight lang="dos">@echo off
for /L %%i in (1,1,100) do call :tester %%i
goto :eof
Line 567 ⟶ 1,254:
:NotFizz
echo %1
</syntaxhighlight>
</lang>
 
Loop version:
 
<langsyntaxhighlight lang="dos">@echo off
set n=1
 
Line 599 ⟶ 1,286:
 
:NotFizz
echo %1</langsyntaxhighlight>
 
FOR /L with a block instead of very-high-overhead subroutine call:
 
<langsyntaxhighlight lang="dos">@echo off & setlocal enabledelayedexpansion
for /l %%i in (1,1,100) do (
set /a m5=%%i %% 5
Line 612 ⟶ 1,299:
if "!s!"=="" set s=%%i
echo !s!
)</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
Line 620 ⟶ 1,307:
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).
 
<langsyntaxhighlight lang="bc">for (i = 1; i <= 100; i++) {
w = 0
if (i % 3 == 0) { "Fizz"; w = 1; }
Line 628 ⟶ 1,315:
"
}
quit</langsyntaxhighlight>
 
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">GET "libhdr"
 
LET start() BE $(
 
FOR i=1 TO 100 DO $(
 
TEST (i REM 15) = 0 THEN
writes("FizzBuzz")
ELSE TEST (i REM 3) = 0 THEN
writes("Fizz")
ELSE TEST (i REM 5) = 0 THEN
writes("Buzz")
ELSE
writen(i, 0)
 
newline()
$)
$)
</syntaxhighlight>
 
=={{header|beeswax}}==
Line 636 ⟶ 1,344:
“Ordinary” FizzBuzz solution:
 
<langsyntaxhighlight lang="beeswax"> > q
>@F5~%"d@F{ > @F q
_1>F3~%'d`Fizz`@F5~%'d >`Buzz`@FNp
;bL@~.~4~.5~5@ P<</langsyntaxhighlight>
 
 
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):
 
<langsyntaxhighlight lang="beeswax"> >@?q
> q >Ag'd@{?p
_>"1F3~%'d`Fizz`f>@F5~%'d`Buzz`@p
b P~;"-~@~.+0~P9@N?<</langsyntaxhighlight>
 
=={{header|Befunge}}==
See [[FizzBuzz/EsoLang]]
 
=={{header|blz}}==
<syntaxhighlight lang="blz">for i = 0; i <= 100; i++
out = ""
if i % 3 == 0
out = "Fizz"
end
if i % 5 == 0
out = out + "Buzz"
end
if out == ""
out = i
end
print(out)
end</syntaxhighlight>
 
=={{header|Boo}}==
<langsyntaxhighlight lang="boo">def fizzbuzz(size):
for i in range(1, size):
if i%15 == 0:
Line 664 ⟶ 1,387:
print i
 
fizzbuzz(101)</langsyntaxhighlight>
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">(∾´∾⟜"Fizz"‿"Buzz"/˜·(¬∨´)⊸∾0=3‿5|⊢)¨1+↕100</syntaxhighlight>
 
Using the Catch modifier for flow control
<syntaxhighlight lang="bqn">((∾´"fizz"‿"buzz"/˜0=3‿5|⊢)⎊⊢)¨1+↕100</syntaxhighlight>
 
Using the Choose Combonator with a rank 2 array
<syntaxhighlight lang="bqn">(3‿5 (0=|)◶[⊢‿"fizz","buzz"‿"fizzbuzz"] ⊢)¨ 1+↕100</syntaxhighlight>
 
=={{header|Bracmat}}==
<langsyntaxhighlight 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))</langsyntaxhighlight>
Same code, pretty printed:
<langsyntaxhighlight lang="bracmat"> 0:?i
& whl
' ( 1+!i:<101:?i
Line 680 ⟶ 1,412:
| !i
)
)</langsyntaxhighlight>
 
=={{header|Brainf***}}==
Line 686 ⟶ 1,418:
 
=={{header|Brat}}==
<langsyntaxhighlight lang="brat">1.to 100 { n |
true? n % 15 == 0
{ p "FizzBuzz" }
Line 696 ⟶ 1,428:
}
}
}</langsyntaxhighlight>
 
=={{header|BrightScript (for Roku)}}==
<syntaxhighlight lang="brightscript">FOR i = 1 TO 100
fz = i MOD 3 = 0
bz = i MOD 5 = 0
IF fz OR bz
IF fz AND NOT bz: str = "Fizz"
ELSEIF bz AND NOT fz: str = "Buzz"
ELSE str = "FizzBuzz"
END IF
ELSE
str = i.ToStr()
END IF
? str
END FOR</syntaxhighlight>
 
=={{header|Bruijn}}==
<syntaxhighlight lang="bruijn">
:import std/Combinator .
:import std/String .
:import std/Number .
 
main [y [[0 =? (+101) case-end case-rec]] (+1)]
case-rec str ++ "\n" ++ (1 ++0)
str fizzbuzz "FizzBuzz" (fizz "Fizz" (buzz "Buzz" (number→string 0)))
fizz =?(0 % (+3))
buzz =?(0 % (+5))
fizzbuzz fizz buzz fizz
case-end empty
</syntaxhighlight>
 
=={{header|C}}==
 
For 2 prime numbers and based on a similar minimal [[#JavaScript|JavaScript]] solution with low signal-to-noise, the C code is:
The following C code was inspired by this ( low SignalToNoise, EasyToModify ) JavaScript:
<syntaxhighlight lang="c"> int i = 0 ; char B[88] ;
<lang JavaScript>for(i=0;i<100;console.log((++i%3?"":"Fizz")+(i%5?"":"Buzz")||i));</lang>
With 2 prime numbers, the C code is:
<lang c> int i = 0 ; char B[88] ;
while ( i++ < 100 )
!sprintf( B, "%s%s", i%3 ? "":"Fizz", i%5 ? "":"Buzz" )
? sprintf( B, "%d", i ):0, printf( ", %s", B );</langsyntaxhighlight>
With 4 prime numbers:
<langsyntaxhighlight lang="c"> int i = 0 ; char B[88] ;
while ( i++ < 100 )
!sprintf( B, "%s%s%s%s",
i%3 ? "":"Fiz", i%5 ? "":"Buz", i%7 ? "":"Goz", i%11 ? "":"Kaz" )
? sprintf( B, "%d", i ):0, printf( ", %s", B );</langsyntaxhighlight>
<langsyntaxhighlight lang="c">Output: ..., 89, FizBuz, Goz, 92, Fiz, 94, Buz, Fiz, 97, Goz, FizKaz, Buz</langsyntaxhighlight>
One line version, with pretty printing
<langsyntaxhighlight lang="c">#include <stdio.h>
 
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");
}
</syntaxhighlight>
</lang>
 
This actually works (the array init part, saves 6 bytes of static data, whee):<langsyntaxhighlight lang="c">#include<stdio.h>
int main ()
{
int i;
const char *s[] = { "%d\n", "Fizz\n", s[3] + 4, "FizzBuzz\n" };
for (i = 1; i <= 100; i++)
printf(s[!(i % 3) + 2 * !(i % 5)], i);
return 0;
 
}</syntaxhighlight>
return 0;
}</lang>
 
<langsyntaxhighlight lang="c">#include<stdio.h>
 
int main (void)
Line 753 ⟶ 1,512:
}
return 0;
}</langsyntaxhighlight>
Implicit int main and return 0 (C99+):
<langsyntaxhighlight lang="c">#include <stdio.h>
main() {
Line 770 ⟶ 1,529:
i++;
}
}</langsyntaxhighlight>
obfuscated:
<langsyntaxhighlight lang="c">#include <stdio.h>
#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;}</langsyntaxhighlight>
 
With numbers theory: <langsyntaxhighlight lang="c">#include <stdio.h>
 
int main(void)
Line 787 ⟶ 1,546:
}
}
</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:
 
<langsyntaxhighlight lang="c">#include <stdio.h>
int main()
{
Line 801 ⟶ 1,560:
}
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#}}==
 
<lang csharp>class Program
<syntaxhighlight lang="csharp">class Program
{
public void FizzBuzzGo()
{
Boolean Fizz = false;
Boolean Buzz = false;
for (int count = 1; count <= 100; count ++)
{
Fizz = count % 3 == 0;
Buzz = count % 5 == 0;
if (Fizz && Buzz)
{
Console.WriteLine("Fizz Buzz");
listBox1.Items.Add("Fizz Buzz");
}
else if (Fizz)
{
Console.WriteLine("Fizz");
listBox1.Items.Add("Fizz");
}
else if (Buzz)
{
Console.WriteLine("Buzz");
listBox1.Items.Add("Buzz");
}
else
{
Console.WriteLine(count);
listBox1.Items.Add(count);
}
}
}
}</syntaxhighlight>
 
<syntaxhighlight lang="csharp">class Program
{
static void Main()
{
for (uint i = 1; i <= 100; i++) {
{
string s = null;
 
if (i % 3 == 0)
s = "Fizz";
 
if (i % 5 == 0)
s += "Buzz";
 
System.Console.WriteLine(s ?? i.ToString());
}
}
}</langsyntaxhighlight>
 
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 837 ⟶ 1,633:
}
}
}</langsyntaxhighlight>
 
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;
using System.Globalization;
using System.Linq;
Line 860 ⟶ 1,657:
}
}
}</langsyntaxhighlight>
 
<lang csharp>using System;
 
<syntaxhighlight lang="csharp">using System;
namespace FizzBuzz
{
Line 891 ⟶ 1,687:
}
}
}</langsyntaxhighlight>
 
<langsyntaxhighlight lang="csharp">using System;
using System.Globalization;
 
Line 922 ⟶ 1,718:
}
}
}</langsyntaxhighlight>
 
TDD using delegates.
<langsyntaxhighlight lang="csharp">using System;
using System.Linq;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
Enumerable.Range(1, 100).ToList().ForEach(i => Console.WriteLine(i % 5 == 0 ? string.Format(i % 3 == 0 ? "Fizz{0}" : "{0}", "Buzz") : string.Format(i%3 == 0 ? "Fizz" : i.ToString())));
}
}
}</syntaxhighlight>
 
===With C#8 switch expressions===
 
<syntaxhighlight lang="csharp">class Program
{
public static string FizzBuzzIt(int n) =>
(n % 3, n % 5) switch
{
(0, 0) => "FizzBuzz",
(0, _) => "Fizz",
(_, 0) => "Buzz",
(_, _) => $"{n}"
};
 
static void Main(string[] args)
{
foreach (var n in Enumerable.Range(1, 100))
{
Console.WriteLine(FizzBuzzIt(n));
}
}
}</syntaxhighlight>
 
===TDD using delegates===
 
<syntaxhighlight lang="csharp">using System;
using System.Collections;
using System.Collections.Generic;
Line 1,006 ⟶ 1,840:
}
}
}</langsyntaxhighlight>
 
===Good old C ways===
<lang csharp>using System;
using System.Linq;
 
<syntaxhighlight lang="csharp">using System;
namespace FizzBuzz
int max = 100;
{
for(int i=0;
class Program
++i<=max;
{
Console.WriteLine("{0}{1}{2}", i%3==0 ? "Fizz" : "", i%5==0 ? "Buzz" : "", i%3!=0 && i%5!=0 ? i.ToString() : "")
static void Main(string[] args)
){}
{
</syntaxhighlight>
Enumerable.Range(1, 100).ToList().ForEach(i => Console.WriteLine(i % 5 == 0 ? string.Format(i % 3 == 0 ? "Fizz{0}" : "{0}", "Buzz") : string.Format(i%3 == 0 ? "Fizz" : i.ToString())));
}
}
}</lang>
 
=={{header|C++}}==
===minimal conditions===
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <chrono>
 
int main()
{
 
int fizz = 0, buzz = 0, fizzbuzz = 0;
 
bool isFizz = false;
 
auto startTime = std::chrono::high_resolution_clock::now();
 
for (unsigned int i = 1; i <= 4000000000; i++) {
isFizz = false;
 
if (i % 3 == 0) {
isFizz = true;
fizz++;
}
 
if (i % 5 == 0) {
if (isFizz) {
fizz--;
fizzbuzz++;
}
else {
buzz++;
}
}
 
}
 
auto endTime = std::chrono::high_resolution_clock::now();
auto totalTime = endTime - startTime;
 
printf("\t fizz : %d, buzz: %d, fizzbuzz: %d, duration %lld milliseconds\n", fizz, buzz, fizzbuzz, (totalTime / std::chrono::milliseconds(1)));
 
return 0;
}
</syntaxhighlight>
===with modulo===
<syntaxhighlight lang="cpp">#include <iostream>
 
using namespace std;
Line 1,040 ⟶ 1,912:
}
return 0;
}</langsyntaxhighlight>
Alternate version not using===without modulo 15:===
<langsyntaxhighlight lang="cpp">#include <iostream>
using namespace std;
 
Line 1,060 ⟶ 1,932:
}
return 0;
}</langsyntaxhighlight>
===without modulo===
 
Alternate version that avoids using modulo. (Modulo can be expensive on some architectures.)
<langsyntaxhighlight lang="cpp">#include <iostream>
 
int main()
Line 1,079 ⟶ 1,951:
return 0;
}
</syntaxhighlight>
</lang>
===using std::transform===
 
A version using std::transform:
{{works with|C++11}}
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <algorithm>
#include <vector>
Line 1,107 ⟶ 1,978:
 
return 0;
}</langsyntaxhighlight>
===metaprogramming===
Version computing FizzBuzz at compile time with metaprogramming:
<langsyntaxhighlight lang="cpp">#include <iostream>
 
template <int n, int m3, int m5>
Line 1,156 ⟶ 2,028:
fb_run<100> fb;
return 0;
}</langsyntaxhighlight>
===hardcore templates===
Hardcore templates (compile with -ftemplate-depth-9000 -std=c++0x):
Compile with -ftemplate-depth-9000 -std=c++0x:
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <string>
#include <cstdlib>
Line 1,321 ⟶ 2,194:
std::cout << mpl::c_str<FizzBuzz<n>::type>::value << std::endl;
return 0;
}</langsyntaxhighlight>
Note: it takes up lots of memory and takes several seconds to compile. To enable compilation for 7 < n <= 25, please, modify include/boost/mpl/limits/string.hpp BOOST_MPL_LIMIT_STRING_SIZE to 128 instead of 32).
 
Line 1,328 ⟶ 2,201:
 
=={{header|Cduce}}==
<langsyntaxhighlight lang="ocaml">(* FizzBuzz in CDuce *)
 
let format (n : Int) : Latin1 =
Line 1,345 ⟶ 2,218:
let fizbuzz (size : Int) : _ = fizz (1, size);;
 
let _ = fizbuzz(100);;</langsyntaxhighlight>
 
=={{header|Ceylon}}==
<langsyntaxhighlight Ceylonlang="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);</langsyntaxhighlight>
 
=={{header|Chapel}}==
<langsyntaxhighlight lang="chapel">proc fizzbuzz(n) {
for i in 1..n do
if i % 15 == 0 then
Line 1,363 ⟶ 2,236:
}
 
fizzbuzz(100);</langsyntaxhighlight>
 
=={{header|Chef}}==
See [[FizzBuzz/EsoLang]]
 
=={{header|Cherrycake}}==
<syntaxhighlight lang="cherrycake">
# Route with custom number of iterations
cached get ~/:n {
 
# Get the Number of Iterations from the URL Params
int n = req.params.n || 100
 
# Loop through each iteration
for (i in range(n)) {
 
if (i % 2 == 0 && i % 3 == 0) { res.write("FizzBuzz\n") continue }
if (i % 2 == 0) { res.write("Fizz\n"); continue; }
if (i % 3 == 0) { res.write("Buzz\n"); continue; }
res.write(i + "\n");
 
}
 
# Close the connection
res.end();
 
}
</syntaxhighlight>
 
=={{header|Clay}}==
<langsyntaxhighlight lang="clay">main() {
for(i in range(1,100)) {
if(i % 3 == 0 and i % 5 == 0) println("fizzbuzz");
Line 1,376 ⟶ 2,273:
else print(i);
}
}</langsyntaxhighlight>
 
=={{header|Clipper}}==
Also compiles with Harbour (Harbour 3.2.0dev (r1405201749))
<langsyntaxhighlight Clipperlang="clipper">PROCEDURE Main()
 
LOCAL n
Line 1,392 ⟶ 2,289:
 
RETURN
</syntaxhighlight>
</lang>
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>
 
=={{header|CLIPS}}==
<langsyntaxhighlight lang="clips">(deffacts count
(count-to 100)
)
Line 1,422 ⟶ 2,319:
(priint depth, unsigned int i> struct NUM_DIGITS_CORE : NUM_DIGITS_COREntout t crlf)
)
)</langsyntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))
</syntaxhighlight>
</lang>
 
<langsyntaxhighlight lang="clojure">
(defn fizzbuzz [start finish]
(map (fn [n]
Line 1,439 ⟶ 2,336:
(range start finish)))
(fizzbuzz 1 100)
</syntaxhighlight>
</lang>
 
<langsyntaxhighlight lang="lisp">(map (fn [x] (cond (zero? (mod x 15)) "FizzBuzz"
(zero? (mod x 5)) "Buzz"
(zero? (mod x 3)) "Fizz"
:else x))
(range 1 101))</langsyntaxhighlight>
<langsyntaxhighlight lang="lisp">(map #(let [s (str (if (zero? (mod % 3)) "Fizz") (if (zero? (mod % 5)) "Buzz"))] (if (empty? s) % s)) (range 1 101))</langsyntaxhighlight>
<langsyntaxhighlight lang="lisp">(def fizzbuzz (map
#(cond (zero? (mod % 15)) "FizzBuzz"
(zero? (mod % 5)) "Buzz"
(zero? (mod % 3)) "Fizz"
:else %)
(iterate inc 1)))</langsyntaxhighlight>
 
<langsyntaxhighlight lang="lisp">(defn fizz-buzz
([] (fizz-buzz (range 1 101)))
([lst]
Line 1,466 ⟶ 2,363:
(buzz? n) b
:else n))
lst)] items))))</langsyntaxhighlight>
<langsyntaxhighlight lang="clojure">(map (fn [n]
(if-let [fb (seq (concat (when (zero? (mod n 3)) "Fizz")
(when (zero? (mod n 5)) "Buzz")))]
(apply str fb)
n))
(range 1 101))</langsyntaxhighlight>
<langsyntaxhighlight lang="clojure">(take 100 (map #(let [s (str %2 %3) ] (if (seq s) s (inc %)) )
(range)
(cycle [ "" "" "Fizz" ])
(cycle [ "" "" "" "" "Buzz" ])))</langsyntaxhighlight>
<langsyntaxhighlight lang="lisp">(map #(nth (conj (cycle [% % "Fizz" % "Buzz" "Fizz" % % "Fizz" "Buzz" % "Fizz" % % "FizzBuzz"]) %) %) (range 1 101))</langsyntaxhighlight>
<langsyntaxhighlight 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)))</langsyntaxhighlight>
<langsyntaxhighlight lang="clojure">(take 100
(map #(if (pos? (compare %1 %2)) %1 %2)
(map str (drop 1 (range)))
(map str (cycle ["" "" "Fizz"]) (cycle ["" "" "" "" "Buzz"]))))
</syntaxhighlight>
</lang>
<langsyntaxhighlight lang="clojure">
;;Using clojure maps
(defn fizzbuzz
Line 1,505 ⟶ 2,402:
[max]
(map fizzbuzz (range 1 (inc max))))
</syntaxhighlight>
</lang>
<langsyntaxhighlight lang="clojure">
(take 100
(map #(str %1 %2 (if-not (or %1 %2) %3))
Line 1,513 ⟶ 2,410:
(rest (range))
))
</syntaxhighlight>
</lang>
 
<langsyntaxhighlight lang="clojure">
(take 100
(
Line 1,534 ⟶ 2,431:
) ;;endfn apply
) ;;endtake
</syntaxhighlight>
</lang>
 
<syntaxhighlight lang="clojure">
(take 100
(map-indexed
#(case %2 14 "FizzBuzz" (2 5 8 11) "Fizz" (4 9) "Buzz" (inc %1))
(cycle (range 15))
)
)
</syntaxhighlight>
 
<syntaxhighlight lang="clojure">
(take 100
(->>
(map str (cycle [nil nil "Fizz"]) (cycle [nil nil nil nil "Buzz"]))
(map-indexed #(if (empty? %2) (inc %1) %2))
)
)
</syntaxhighlight>
 
<syntaxhighlight lang="clojure">
(take 100
(map-indexed
#(if (number? %2) (+ %1 %2) %2)
(cycle [1 1 "Fizz" 1 "Buzz" "Fizz" 1 1 "Fizz" "Buzz" 1 "Fizz" 1 1 "FizzBuzz"])
)
)
</syntaxhighlight>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">start_up = proc ()
po: stream := stream$primary_output()
for i: int in int$from_to(1, 100) do
out: string := ""
if i // 3 = 0 then out := out || "Fizz" end
if i // 5 = 0 then out := out || "Buzz" end
if string$empty(out) then out := int$unparse(i) end
stream$putl(po, out)
end
end start_up</syntaxhighlight>
 
=={{header|CMake}}==
<langsyntaxhighlight lang="cmake">foreach(i RANGE 1 100)
math(EXPR off3 "${i} % 3")
math(EXPR off5 "${i} % 5")
Line 1,549 ⟶ 2,486:
message(${i})
endif()
endforeach(i)</langsyntaxhighlight>
 
=={{header|COBOL}}==
Line 1,555 ⟶ 2,492:
===Canonical version===
{{works with|OpenCOBOL}}<!-- http://www.opencobol.org/ -->
<langsyntaxhighlight COBOLlang="cobol"> * FIZZBUZZ.COB
* cobc -x -g FIZZBUZZ.COB
*
Line 1,590 ⟶ 2,527:
END-PERFORM
DISPLAY ""
STOP RUN.</langsyntaxhighlight>
===Simpler version===
I know this doesn't have the full-bodied, piquant flavor
expected from COBOL, but it is a little shorter.
{{works with|OpenCOBOL}}
<langsyntaxhighlight lang="cobol">Identification division.
Program-id. fizz-buzz.
 
Line 1,610 ⟶ 2,547:
else display num
end-perform.
Stop run.</langsyntaxhighlight>
===Evaluate Version===
I think this shows clearly that it's resolving the problem and illuminating the rules specified
{{works with|OpenCOBOL}}
<langsyntaxhighlight lang="cobol">
IDENTIFICATION DIVISION.
PROGRAM-ID. FIZZBUZZ.
Line 1,641 ⟶ 2,578:
STOP RUN
.
</syntaxhighlight>
</lang>
 
===Chase the Fizz===
{{works with|OpenCOBOL}}
A solution that simply evaluates and adds.
<langsyntaxhighlight lang="cobol"> >>SOURCE FORMAT FREE
identification division.
program-id. fizzbuzz.
Line 1,675 ⟶ 2,612:
.
end program fizzbuzz.
</syntaxhighlight>
</lang>
 
=={{header|Coco}}==
<langsyntaxhighlight lang="coco">for i from 1 to 100
console.log do
if i % 15 == 0 then 'FizzBuzz'
else if i % 3 == 0 then 'Fizz'
else if i % 5 == 0 then 'Buzz'
else i</langsyntaxhighlight>
 
<syntaxhighlight lang="coco">for i from 1 to 100
console.log(['Fizz' unless i % 3] + ['Buzz' unless i % 5] or String(i))</syntaxhighlight>
 
=={{header|Coconut}}==
<lang coco>for i from 1 to 100
<syntaxhighlight lang="coconut">def fizzbuzz(n):
console.log(['Fizz' unless i % 3] + ['Buzz' unless i % 5] or String(i))</lang>
case (n % 3, n % 5):
match (0, 0): return "FizzBuzz"
match (0, _): return "Fizz"
match (_, 0): return "Buzz"
else: return n |> str
range(1,101)|> map$(fizzbuzz)|> x -> '\n'.join(x)|> print</syntaxhighlight>
 
=={{header|CoffeeScript}}==
<langsyntaxhighlight CoffeeScriptlang="coffeescript">for i in [1..100]
if i % 15 is 0
console.log "FizzBuzz"
Line 1,697 ⟶ 2,643:
console.log "Buzz"
else
console.log i</langsyntaxhighlight>
<langsyntaxhighlight CoffeeScriptlang="coffeescript">for i in [1..100]
console.log \
if i % 15 is 0
Line 1,707 ⟶ 2,653:
"Buzz"
else
i</langsyntaxhighlight>
<langsyntaxhighlight CoffeeScriptlang="coffeescript">for i in [1..100]
console.log(['Fizz' if i % 3 is 0] + ['Buzz' if i % 5 is 0] or i)</langsyntaxhighlight>
 
=={{header|ColdFusion}}==
<langsyntaxhighlight lang="cfm"><Cfloop from="1" to="100" index="i">
<Cfif i mod 15 eq 0>FizzBuzz
<Cfelseif i mod 5 eq 0>Fizz
Line 1,718 ⟶ 2,664:
<Cfelse><Cfoutput>#i# </Cfoutput>
</Cfif>
</Cfloop></langsyntaxhighlight>
cfscript version
<langsyntaxhighlight lang="cfm"><cfscript>
result = "";
for(i=1;i<=100;i++){
Line 1,726 ⟶ 2,672:
}
WriteOutput(result);
</cfscript></langsyntaxhighlight>
 
=={{header|Comal}}==
<syntaxhighlight lang="comal">0010 FOR i#:=1 TO 100 DO
0020 IF i# MOD 15=0 THEN
0030 PRINT "FizzBuzz"
0040 ELIF i# MOD 5=0 THEN
0050 PRINT "Buzz"
0060 ELIF i# MOD 3=0 THEN
0070 PRINT "Fizz"
0080 ELSE
0090 PRINT i#
0100 ENDIF
0110 ENDFOR i#
0120 END</syntaxhighlight>
 
=={{header|Comefrom0x10}}==
 
<langsyntaxhighlight lang="cf0x10">fizzbuzz
mod_three = 3
mod_five = 5
Line 1,753 ⟶ 2,713:
mod_five = mod_five + 5
 
comefrom fizzbuzz if n is 100</langsyntaxhighlight>
 
=={{header|Commodore BASIC}}==
See [[FizzBuzz/Basic]]
 
=={{header|Common Lisp}}==
Solution 1:
<langsyntaxhighlight lang="lisp">(defun fizzbuzz ()
(loop for x from 1 to 100 do
(princ (cond ((zerop (mod x 15)) "FizzBuzz")
Line 1,763 ⟶ 2,726:
((zerop (mod x 5)) "Buzz")
(t x)))
(terpri)))</langsyntaxhighlight>
Solution 2:
<langsyntaxhighlight lang="lisp">(defun fizzbuzz ()
(loop for x from 1 to 100 do
(format t "~&~{~A~}"
(or (append (when (zerop (mod x 3)) '("Fizz"))
(when (zerop (mod x 5)) '("Buzz")))
(list x)))))</langsyntaxhighlight>
Solution 3:
<langsyntaxhighlight lang="lisp">(defun fizzbuzz ()
(loop for n from 1 to 100
do (format t "~&~[~[FizzBuzz~:;Fizz~]~*~:;~[Buzz~*~:;~D~]~]~%"
(mod n 3) (mod n 5) n)))</langsyntaxhighlight>
Solution 4:
<langsyntaxhighlight lang="lisp">(loop as n from 1 to 100
as fizz = (zerop (mod n 3))
as buzz = (zerop (mod n 5))
Line 1,784 ⟶ 2,747:
(format t
"~&~:[~;Fizz~]~:[~;Buzz~]~:[~;~D~]~%"
fizz buzz numb n))</langsyntaxhighlight>
Solution 5:
<langsyntaxhighlight lang="lisp">(format t "~{~:[~&~;~:*~:(~a~)~]~}"
(loop as n from 1 to 100
as f = (zerop (mod n 3))
Line 1,793 ⟶ 2,756:
if f collect 'fizz
if b collect 'buzz
if (not (or f b)) collect n))</langsyntaxhighlight>
Solution 6:
<langsyntaxhighlight lang="lisp">(format t "~{~{~:[~;Fizz~]~:[~;Buzz~]~:[~*~;~d~]~}~%~}"
(loop as n from 1 to 100
as f = (zerop (mod n 3))
as b = (zerop (mod n 5))
collect (list f b (not (or f b)) n)))</langsyntaxhighlight>
 
Solution 7:
<langsyntaxhighlight lang="lisp">(defun core (x)
(mapcar
#'(lambda (a b) (if (equal 0 (mod x a)) b x))
Line 1,817 ⟶ 2,780:
(print (format nil "~{~a~}" (filter-core (core a))))))
 
(fizzbuzz 100)</langsyntaxhighlight>
 
Solution 8:
<syntaxhighlight lang="lisp">(defun range (min max)
(loop
:for x :from min :to max
:collect x))
 
(defun fizzbuzz ()
(map 'nil #'(lambda (n)
(princ
(cond
((zerop (mod n 15)) "FizzBuzz!")
((zerop (mod n 5)) "Buzz!")
((zerop (mod n 3)) "Fizz!")
(t n))
(terpri)))
(range 1 100)))</syntaxhighlight>
 
First 16 lines of output:
<pre>
Line 1,837 ⟶ 2,818:
16
</pre>
 
=== Alternate solution ===
I use [https://franz.com/downloads/clp/survey Allegro CL 10.1]
 
<syntaxhighlight lang="lisp">
;; Project : FizzBuzz
 
(defun fizzbuzz (&optional n)
(let ((n (or n 1)))
(if (> n 100)
nil
(progn
(let ((mult-3 (is-mult-p n 3))
(mult-5 (is-mult-p n 5)))
(if mult-3
(princ "Fizz"))
(if mult-5
(princ "Buzz"))
(if (not (or mult-3 mult-5))
(princ n))
(princ #\linefeed)
(fizzbuzz (+ n 1)))))))
(defun is-mult-p (n multiple)
(= (rem n multiple) 0))
(fizzbuzz 1)
</syntaxhighlight>
Output:
<pre>
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
</pre>
 
=={{header|Coq}}==
 
<syntaxhighlight lang="coq">
Require Import Coq.Lists.List.
(* https://coq.inria.fr/library/Coq.Lists.List.html *)
 
Require Import Coq.Strings.String.
(* https://coq.inria.fr/library/Coq.Strings.String.html *)
 
Require Import Coq.Strings.Ascii.
(* https://coq.inria.fr/library/Coq.Strings.Ascii.html *)
 
Require Import Coq.Init.Nat.
(* https://coq.inria.fr/library/Coq.Init.Nat.html *)
 
 
(** Definition of [string_of_nat] to convert natural numbers to strings. *)
 
Definition ascii_of_digit (n : nat) : ascii :=
ascii_of_nat (n + 48).
 
Definition is_digit (n : nat) : bool :=
andb (0 <=? n) (n <=? 9).
 
Fixpoint rec_string_of_nat (counter : nat) (n : nat) (acc : string) : string :=
match counter with
| 0 => EmptyString
| S c =>
if (is_digit n)
then String (ascii_of_digit n) acc
else rec_string_of_nat c (n / 10) (String (ascii_of_digit (n mod 10)) acc)
end.
(** The counter is only used to ensure termination. *)
 
Definition string_of_nat (n : nat) : string :=
rec_string_of_nat n n EmptyString.
 
 
(** The FizzBuzz problem. *)
 
Definition fizz : string :=
"Fizz".
 
Definition buzz : string :=
"Buzz".
 
Definition new_line : string :=
String (ascii_of_nat 10) EmptyString.
 
Definition is_divisible_by (n : nat) (k : nat) : bool :=
(n mod k) =? 0.
 
Definition get_term (n : nat) : string :=
if (is_divisible_by n 15) then fizz ++ buzz
else if (is_divisible_by n 3) then fizz
else if (is_divisible_by n 5) then buzz
else (string_of_nat n).
 
Definition range (a : nat) (b : nat) : list nat :=
seq a b.
 
Definition get_terms (n : nat) : list string :=
map get_term (range 1 n).
 
Definition fizz_buzz : string :=
concat new_line (get_terms 100).
 
(** This shows the string. *)
Eval compute in fizz_buzz.
</syntaxhighlight>
 
Output
 
<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"%string
: string
</pre>
 
=={{header|Cowgol}}==
 
===Straightforward version===
 
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
var i: uint8 := 1;
while i <= 100 loop
if i % 15 == 0 then
print("FizzBuzz");
elseif i % 5 == 0 then
print("Buzz");
elseif i % 3 == 0 then
print("Fizz");
else
print_i8(i);
end if;
print_nl();
i := i + 1;
end loop;</syntaxhighlight>
 
===No division===
 
When targeting small systems, it is generally a good idea not to use division
if you don't have to. Most of the processors Cowgol targets do not have
hardware division, requiring the use of slow and bulky software division routines.
This is not helped by the fact that these processors are not fast to begin with,
and memory is usually scarce.
 
Avoiding division requires not only that <code>%</code> be avoided, but also
<code>print_i8</code> cannot be used, as printing integers in decimal format
is also done by division. Instead, this code keeps separate 'fizz' and 'buzz'
counters around, as well as keeping the number ready in ASCII format for printing.
Nevertheless, the following code compiles to a
252-byte 8080 executable, whereas the naive version above compiles to a 755-byte
executable. (Compare to the 8080 assembly program above, which assembles to a
98-byte executable.)
 
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
var i: uint8 := 100;
var fizz: uint8 := 3;
var buzz: uint8 := 5;
var dh: uint8 := '0';
var dl: uint8 := '1';
var prnum: uint8;
 
while i != 0 loop
fizz := fizz - 1;
buzz := buzz - 1;
prnum := 1;
 
if fizz == 0 then
print("Fizz");
fizz := 3;
prnum := 0;
end if;
if buzz == 0 then
print("Buzz");
buzz := 5;
prnum := 0;
end if;
if prnum != 0 then
if dh != '0' then
print_char(dh);
end if;
print_char(dl);
end if;
dl := dl + 1;
if dl == ('9' + 1) then
dl := '0';
dh := dh + 1;
end if;
print_nl();
i := i - 1;
end loop;
</syntaxhighlight>
 
=={{header|Craft Basic}}==
See [[FizzBuzz/Basic]]
 
=={{header|Crystal}}==
<langsyntaxhighlight lang="ruby">1.upto(100) do |v|
p fizz_buzz(v)
end
Line 1,849 ⟶ 3,141:
word += value.to_s if word.empty?
word
end</langsyntaxhighlight>
 
A more natural solution with the string building:
 
<syntaxhighlight lang="ruby">1.upto(100) do |n|
case
when n % 15 == 0
puts "FizzBuzz"
when n % 5 == 0
puts "Buzz"
when n % 3 == 0
puts "Fizz"
else
puts n
end
end</syntaxhighlight>
 
=={{header|CSS}}==
<pre style="font-size:84%;height:75ex">
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<style>
li {
list-style-position: inside;
}
li:nth-child(3n), li:nth-child(5n) {
list-style-type: none;
}
li:nth-child(3n)::before {
content:'Fizz';
}
li:nth-child(5n)::after {
content:'Buzz';
}
</style>
</head>
<body>
<ol>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ol>
</body>
</html>
</pre>
 
=={{header|Cubescript}}==
<syntaxhighlight lang="text">alias fizzbuzz [
loop i 100 [
push i (+ $i 1) [
Line 1,866 ⟶ 3,300:
]
]
]</langsyntaxhighlight>
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.stdio, std.algorithm, std.conv;
 
/// With if-else.
Line 1,921 ⟶ 3,355:
writeln;
100.fizzBuzzSwitch2;
}</langsyntaxhighlight>
Alternate version calculating values at compile time:
<syntaxhighlight lang="d">import std;
 
void main()
{
auto fizzbuzz(in uint i)
{
string r;
if (i % 3 == 0) r ~= "fizz";
if (i % 5 == 0) r ~= "buzz";
if (r.length == 0) r ~= i.to!string;
return r;
}
enum r = 1.iota(101).map!fizzbuzz;
 
r.each!writeln;
}</syntaxhighlight>
 
=={{header|Dart}}==
<langsyntaxhighlight lang="dart">
main() {
for (int i = 1; i <= 100; i++) {
Line 1,935 ⟶ 3,387:
}
}
</syntaxhighlight>
</lang>
 
=={{header|dc}}==
{{trans|bc}}
<langsyntaxhighlight lang="dc">[[Fizz]P 1 sw]sF
[[Buzz]P 1 sw]sB
[li p sz]sN
Line 1,954 ⟶ 3,406:
]sL
1 si [i = 1]sz
0 0 =L [enter Loop]sz</langsyntaxhighlight>
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
# current number.
Line 1,974 ⟶ 3,426:
1+d # Number += 1 and put extra copy on stack
100!<L # Continue Loop if 100 >= Number (destroys copy)
]dsLx # Enter Loop</langsyntaxhighlight>
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">program FizzBuzz;
 
{$APPTYPE CONSOLE}
Line 1,997 ⟶ 3,449:
Writeln(i);
end;
end.</langsyntaxhighlight>
 
=={{header|DeviousYarn}}==
<langsyntaxhighlight lang="deviousyarn">each { x range(1 100)
? { divisible(x 3)
p:'Fizz' }
Line 2,008 ⟶ 3,460:
p:x }
o
}</langsyntaxhighlight>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec main() void:
byte i;
for i from 1 upto 100 do
if i % 15 = 0 then writeln("FizzBuzz")
elif i % 5 = 0 then writeln("Buzz")
elif i % 3 = 0 then writeln("Fizz")
else writeln(i)
fi
od
corp</syntaxhighlight>
 
=={{header|DUP}}==
 
FizzBuzz, realized using two different methods for string/character output:
 
Output to STDOUT via single character 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}</syntaxhighlight>
 
Output to STDOUT, using stored strings and a separately defined string output operator:
<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}
0[$100<][1+c;!]# {loop from 1 to 100}</syntaxhighlight>
 
=={{header|DWScript}}==
<langsyntaxhighlight lang="delphi">var i : Integer;
 
for i := 1 to 100 do begin
Line 2,021 ⟶ 3,498:
PrintLn('Buzz')
else PrintLn(i);
end;</langsyntaxhighlight>
 
=={{header|Dyalect}}==
 
<syntaxhighlight lang="dyalect">var n = 1
 
while n < 20 {
if n % 15 == 0 {
print("fizzbuzz")
} else if n % 3 == 0 {
print("fizz")
} else if n % 5 == 0 {
print("buzz")
} else {
print(n)
}
 
n = n + 1
}</syntaxhighlight>
 
{{out}}
 
<pre>1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19</pre>
 
=={{header|Déjà Vu}}==
<langsyntaxhighlight lang="dejavu">for i range 1 100:
if = 0 % i 15:
"FizzBuzz"
Line 2,033 ⟶ 3,550:
else:
i
!print</langsyntaxhighlight>
 
=={{header|DUP}}==
 
FizzBuzz, realized using two different methods for string/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}
0[$100<][1+c;!]# {loop from 1 to 100}</lang>
 
Output to STDOUT, using stored strings and a separately defined string output operator:
<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}
0[$100<][1+c;!]# {loop from 1 to 100}</lang>
 
=={{header|E}}==
<langsyntaxhighlight lang="e">for i in 1..100 {
println(switch ([i % 3, i % 5]) {
match [==0, ==0] { "FizzBuzz" }
Line 2,056 ⟶ 3,560:
match _ { i }
})
}</langsyntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="text">for i = 1 to 100
if i mod 15 = 0
print "FizzBuzz"
elif i mod 5 = 0
print "Buzz"
elif i mod 3 = 0
print "Fizz"
else
print i
.
.</syntaxhighlight>
 
=={{header|ECL}}==
<langsyntaxhighlight ECLlang="ecl">DataRec := RECORD
STRING s;
END;
Line 2,075 ⟶ 3,592:
d := DATASET(100,MakeDataRec(COUNTER));
 
OUTPUT(d);</langsyntaxhighlight>
 
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">
module FizzBuzz {
void run() {
@Inject Console console;
for (Int x : 1..100) {
console.print(switch (x % 3, x % 5) {
case (0, 0): "FizzBuzz";
case (0, _): "Fizz";
case (_, 0): "Buzz";
case (_, _): x.toString();
});
}
}
}
</syntaxhighlight>
 
=={{header|Eero}}==
<langsyntaxhighlight lang="objc">#import <Foundation/Foundation.h>
 
int main()
Line 2,091 ⟶ 3,625:
Log( '(%d) %@', i, s )
 
return 0</langsyntaxhighlight>
 
=={{header|Egel}}==
<syntaxhighlight lang="egel">
import "prelude.eg"
import "io.ego"
 
using System
using IO
 
def fizzbuzz =
[ 100 -> print "100\n"
| N ->
if and ((N%3) == 0) ((N%5) == 0) then
let _ = print "fizz buzz, " in fizzbuzz (N+1)
else if (N%3) == 0 then
let _ = print "fizz, " in fizzbuzz (N+1)
else if (N%5) == 0 then
let _ = print "buzz, " in fizzbuzz (N+1)
else
let _ = print N ", " in fizzbuzz (N+1) ]
 
def main = fizzbuzz 1
</syntaxhighlight>
 
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">
<lang Eiffel>
class
APPLICATION
Line 2,129 ⟶ 3,686:
end
 
</syntaxhighlight>
</lang>
 
=={{header|Ela}}==
<langsyntaxhighlight lang="ela">open list
 
prt x | x % 15 == 0 = "FizzBuzz"
Line 2,139 ⟶ 3,696:
| else = x
 
[1..100] |> map prt</langsyntaxhighlight>
 
=={{header|Elixir}}==
===Standard approaches===
used case
<langsyntaxhighlight lang="elixir">Enum.each 1..100, fn x ->
IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do
{ true, true } -> "FizzBuzz"
Line 2,151 ⟶ 3,708:
{ false, false } -> x
end)
end</langsyntaxhighlight>
 
Alternate approach using pipes and cond:
 
<langsyntaxhighlight lang="elixir">#!/usr/bin/env elixir
1..100 |> Enum.map(fn i ->
cond do
Line 2,163 ⟶ 3,720:
true -> i
end
end) |> Enum.each(fn i -> IO.puts i end)</langsyntaxhighlight>
 
used Stream.cycle version:
<langsyntaxhighlight lang="elixir">defmodule RC do
def fizzbuzz(limit \\ 100) do
fizz = Stream.cycle(["", "", "Fizz"])
Line 2,179 ⟶ 3,736:
end
 
RC.fizzbuzz</langsyntaxhighlight>
 
Yet another approach:
<langsyntaxhighlight lang="elixir">defmodule FizzBuzz do
def fizzbuzz(n) when rem(n, 15) == 0, do: "FizzBuzz"
def fizzbuzz(n) when rem(n, 5) == 0, do: "Buzz"
Line 2,189 ⟶ 3,746:
end
 
Enum.each(1..100, &IO.puts FizzBuzz.fizzbuzz &1)</langsyntaxhighlight>
 
used anonymous function
<langsyntaxhighlight lang="elixir">f = fn(n) when rem(n,15)==0 -> "FizzBuzz"
(n) when rem(n,5)==0 -> "Fizz"
(n) when rem(n,3)==0 -> "Buzz"
Line 2,198 ⟶ 3,755:
end
 
for n <- 1..100, do: IO.puts f.(n)</langsyntaxhighlight>
 
Enum.at version: Returns nil if index is out of bounds.
<langsyntaxhighlight lang="elixir">Enum.each(1..100, fn i ->
str = "#{Enum.at([:Fizz], rem(i,3))}#{Enum.at([:Buzz], rem(i,5))}"
IO.puts if str=="", do: i, else: str
end)</langsyntaxhighlight>
 
===A macro too far===
The Stream.cycle version above, but as an overpowered FizzBuzz DSL.
<langsyntaxhighlight lang="elixir">defmodule BadFizz do
# Hand-rolls a bunch of AST before injecting the resulting FizzBuzz code.
defmacrop automate_fizz(fizzers, n) do
Line 2,298 ⟶ 3,855:
end
 
BadFizz.fizz(100) # => Prints to stdout</langsyntaxhighlight>
 
=={{header|Elm}}==
A bit too simple:
<langsyntaxhighlight lang="elm">import Graphics.ElementHtml exposing (showtext)
import List exposing (map)
 
main =
map getWordForNum [1..100] |> showmap getWordForNum |> text
 
getWordForNum num =
Line 2,316 ⟶ 3,873:
"Buzz"
else
toStringString.fromInt num</langsyntaxhighlight>
 
A bit too clever:
<langsyntaxhighlight lang="elm">import Html exposing (text)
import List exposing (map)
import String exposing (join, fromInt)
 
main : Html.Html
main =
map fizzbuzz [1..100] |> map fizzbuzz |> join " " |> text
 
fizzbuzz : Int -> String
Line 2,334 ⟶ 3,891:
in
if fizz == buzz then
toStringfromInt num
else
fizz ++ buzz</langsyntaxhighlight>
 
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(defun fizzbuzz (n)
(cond ((and (zerop (% n 5)) (zerop (% n 3))) "FizzBuzz")
((zerop (% n 3)) "Fizz")
((zerop (% n 5)) "Buzz")
(t n)))
 
;; loop & print from 0 to 100
(dotimes (i 101)
(message "%s" (fizzbuzz i)))</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
logic isFizz, isBuzz
for int count = 1; count <= 100; ++count
isFizz = count % 3 == 0
isBuzz = count % 5 == 0
if isFizz and isBuzz do writeLine("Fizz Buzz")
else if isFizz do writeLine("Fizz")
else if isBuzz do writeLine("Buzz")
else do writeLine(count)
end
end
</syntaxhighlight>
 
=={{header|Emojicode}}==
===Simple 1===
<syntaxhighlight lang="emojicode">🏁🍇
🔂 i 🆕⏩ 1 101 1 ❗ 🍇
↪️ i 🚮 15 🙌 0 🍇
😀 🔤FizzBuzz🔤 ❗
🍉
🙅↪️ i 🚮 3 🙌 0 🍇
😀 🔤Fizz🔤 ❗
🍉
🙅↪️ i 🚮 5 🙌 0 🍇
😀 🔤Buzz🔤 ❗
🍉🙅🍇
😀 🔤🧲i🧲🔤 ❗
🍉
🍉
🍉</syntaxhighlight>
===Simple 2===
<syntaxhighlight lang="emojicode">🏁🍇
🔂 i 🆕⏩ 1 101 1 ❗ 🍇
🔤🔤 ➡️ 🖍🆕 msg
↪️ i 🚮 3 🙌 0 🍇
🔤Fizz🔤 ➡️ 🖍 msg
🍉
↪️ i 🚮 5 🙌 0 🍇
🔤🧲msg🧲Buzz🔤 ➡️ 🖍 msg
🍉
↪️ msg 🙌 🔤🔤 🍇
😀 🔤🧲i🧲🔤 ❗
🍉🙅🍇
😀 🔤🧲msg🧲🔤 ❗
🍉
🍉
🍉</syntaxhighlight>
 
=={{header|Enguage}}==
<syntaxhighlight lang="Enguage">FizzBuzz</syntaxhighlight>
 
This source code is supposed to look like plain old English but is, in fact, executable. When used in an Android app, it gives the user direct access to computational abilities of your phone.
 
It is taken from [https://bitbucket.org/martinwheatman/enguage/src/develop/etc/dict/f/fizzbuzz.entry the dictionary entry for fizzbuzz]
 
This shows the interpretation of two utterances, the latter of which are called recursively. Enguage is not very efficient, but that's not its goal!
 
NB. Any line beginning with a '#' is a comment, like Unix shells, but any comment following the ']' character are unit tests exercising this code.
 
<pre>
On "what is the fizzbuzz of N":
is N divisible by 5 and 3;
if so, reply "fizzbuzz";
is N divisible by 5;
if so, reply "buzz";
is N divisible by 3;
if so, reply "fizz";
reply "N".
On "do fizzbuzz between N and LIMIT":
what is the fizzbuzz of N;
remember this;
set next to the evaluation of N + 1;
NEXT is equal to LIMIT;
if so, what is the fizzbuzz of LIMIT;
if not, do fizzbuzz between NEXT and LIMIT.
#] what is the fizzbuzz of 1: 1.
#] what is the fizzbuzz of 12: fizz.
#] what is the fizzbuzz of 25: buzz.
#] what is the fizzbuzz of 75: fizzbuzz.
 
#] set limit to 5.
#] do fizzbuzz between 1 and LIMIT.
</pre>
 
On downloading this repo, if git and make are installed, this unit test can be run with:
<pre>
$ git clone https://github.com/martinwheatman/enguage.git
$ cd enguage
$ make jar
$ export PATH=$PATH:./sbin
$ java -jar lib/enguage.jar -T fizzbuzz
</pre>
 
Output:
<pre>
TEST: fizzbuzz
==============
 
user> what is the fizzbuzz of 1.
enguage> 1.
 
user> what is the fizzbuzz of 12.
enguage> fizz.
 
user> what is the fizzbuzz of 25.
enguage> buzz.
 
user> what is the fizzbuzz of 75.
enguage> fizzbuzz.
 
user> set limit to 5.
enguage> ok , limit is set to 5.
 
user> do fizzbuzz between 1 and LIMIT.
enguage> 1 . 2 . fizz . 4 . buzz.
1 test group(s) found
+++ PASSED 6 tests in 442ms +++
</pre>
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">-spec fizzbuzz() -> Result :: string().
fizzbuzz() ->
F = fun(N) when N rem 15 == 0 -> "FizzBuzz";
(N) when N rem 3 == 0 -> "Fizz";
Line 2,345 ⟶ 4,039:
(N) -> integer_to_list(N)
end,
lists:flatten([[F(N)] ++ ["\n"] || N <- lists:seq(1,100)]).</langsyntaxhighlight>
 
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
<lang ERRE>
PROGRAM FIZZ_BUZZ
!
Line 2,366 ⟶ 4,060:
END FOR
END PROGRAM
</syntaxhighlight>
</lang>
 
=={{header|Euler}}==
The original Euler implementations did not allow "long" strings, hence the use of a list here to print FizzBuzz.
'''begin''' '''new''' i; '''label''' iLoop;
i &lt;- 0;
iLoop: '''if''' [ i &lt;- i + 1 ] &lt;= 100 '''then''' '''begin'''
'''out''' '''if''' i '''mod''' 15 = 0 '''then''' ( "Fizz", "Buzz" )
'''else''' '''if''' i '''mod''' 5 = 0 '''then''' "Buzz"
'''else''' '''if''' i '''mod''' 3 = 0 '''then''' "Fizz"
'''else''' i;
'''goto''' iLoop
'''end''' '''else''' 0
'''end''' $
 
=={{header|Euphoria}}==
{{works with|Euphoria|4.0.0}}
This is based on the [[VBScript]] example.
<langsyntaxhighlight Euphorialang="euphoria">include std/utils.e
 
function fb( atom n )
Line 2,403 ⟶ 4,110:
end for
 
puts( 1, "\n" )</langsyntaxhighlight>
 
=={{header|F Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">let fizzbuzz n =
match n%3 = 0, n%5 = 0 with
| true, false -> "fizz"
Line 2,414 ⟶ 4,121:
 
let printFizzbuzz() =
[1..100] |> List.iter (fizzbuzz >> printfn "%s")</langsyntaxhighlight>
<langsyntaxhighlight lang="fsharp">[1..100]
|> List.map (fun x ->
match x with
Line 2,422 ⟶ 4,129:
| _ when x % 3 = 0 -> "fizz"
| _ -> x.ToString())
|> List.iter (fun x -> printfn "%s" x) </langsyntaxhighlight>
Another example using (unnecessary) partial active pattern :D
<langsyntaxhighlight lang="fsharp">let (|MultipleOf|_|) divisors number =
if Seq.exists ((%) number >> (<>) 0) divisors
then None
Line 2,436 ⟶ 4,143:
 
{ 1 .. 100 }
|> Seq.iter (fizzbuzz >> printfn "%s")</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: math kernel io math.functions math.parser math.ranges ;
IN: fizzbuzz
: fizz ( n -- str ) 3 divisor? "Fizz" "" ? ;
Line 2,445 ⟶ 4,152:
: fizzbuzz ( n -- str ) dup [ fizz ] [ buzz ] bi append [ number>string ] [ nip ] if-empty ;
: main ( -- ) 100 [1,b] [ fizzbuzz print ] each ;
MAIN: main</langsyntaxhighlight>
 
More flexible variant without divisibility tests.
<syntaxhighlight lang="factor">
USING: kernel sequences arrays generalizations fry math math.parser prettyprint ;
IN: fizzbuzz
 
: zz ( m seq -- v ) dup length 1 <array> V{ } clone 4 -nrot 1 4 -nrot 3 nrot
'[ dup _ <= ]
3 -nrot
'[
"" _ [ _ [ swap execute( str n -- str n ) ] change-nth ] each-index
dup empty? [ drop dup number>string ] [ ] if swapd suffix! swap 1 +
]
while drop ;
 
: fizz ( str n -- str n ) dup 3 < [ 1 + ] [ drop "Fizz" append 1 ] if ;
: buzz ( str n -- str n ) dup 5 < [ 1 + ] [ drop "Buzz" append 1 ] if ;
: quxx ( str n -- str n ) dup 7 < [ 1 + ] [ drop "Quxx" append 1 ] if ;
: FizzBuzzQuxx ( m -- v ) { fizz buzz quxx } zz ;
: FizzBuzzQuxx-100 ( -- ) 100 FizzBuzzQuxx . ;
 
MAIN: FizzBuzzQuxx-100
</syntaxhighlight>
 
Another approach is leverage Factor's [https://docs.factorcode.org/content/article-predicates.html predicate] and [https://docs.factorcode.org/content/article-intersections.html intersection] classes.
<syntaxhighlight lang="factor">
USING: io kernel math math.functions math.parser ranges
sequences ;
IN: rosetta-code.fizz-buzz
 
PREDICATE: fizz < integer 3 divisor? ;
PREDICATE: buzz < integer 5 divisor? ;
 
INTERSECTION: fizzbuzz fizz buzz ;
 
GENERIC: fizzbuzz>string ( n -- str )
 
M: fizz fizzbuzz>string
drop "Fizz" ;
 
M: buzz fizzbuzz>string
drop "Buzz" ;
 
M: fizzbuzz fizzbuzz>string
drop "FizzBuzz" ;
 
M: integer fizzbuzz>string
number>string ;
 
MAIN: [ 1 100 [a..b] [ fizzbuzz>string print ] each ]
</syntaxhighlight>
 
=={{header|Falcon}}==
<langsyntaxhighlight lang="falcon">for i in [1:101]
switch i % 15
case 0 : > "FizzBuzz"
Line 2,455 ⟶ 4,213:
default : > i
end
end</langsyntaxhighlight>
 
=={{header|FALSE}}==
Line 2,461 ⟶ 4,219:
 
=={{header|Fantom}}==
<langsyntaxhighlight lang="fantom">class FizzBuzz
{
public static Void main ()
Line 2,477 ⟶ 4,235:
}
}
}</langsyntaxhighlight>
 
=={{header|FBSL}}==
'''No 'MOD 15' needed.'''
<langsyntaxhighlight lang="qbasic">#APPTYPE CONSOLE
 
DIM numbers AS STRING
Line 2,497 ⟶ 4,255:
NEXT
 
PAUSE</langsyntaxhighlight>
{{out}}
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fiz
Line 2,506 ⟶ 4,264:
98 Fizz Buzz
Press any key to continue...
 
=={{header|Fe}}==
There is no built-in ''mod'' function, but you can add it via the C API.
<syntaxhighlight lang="c">
static fe_Object *mod(fe_Context *ctx, fe_Object *args) {
fe_Number n = fe_tonumber(ctx, fe_nextarg(ctx, &args));
return fe_number(ctx, fmod(n, fe_tonumber(ctx, fe_nextarg(ctx, &args))));
}
</syntaxhighlight>
Then, you can solve 'FizzBuzz' the traditional way:
<syntaxhighlight lang="clojure">
(= i 0)
(while (< i 100)
(= i (+ i 1))
(print
(if (is (mod i 15) 0) "FizzBuzz"
(is (mod i 3) 0) "Fizz"
(is (mod i 5) 0) "Buzz"
i)))
</syntaxhighlight>
Of course, you can solve this without ''mod'':
<syntaxhighlight lang="clojure">
(= i 0)
(= fizz 0)
(= buzz 0)
(= fizzbuzz 0)
 
(while (< i 100)
(= i (+ i 1))
(= fizz (+ fizz 1))
(= buzz (+ buzz 1))
(= fizzbuzz (+ fizzbuzz 1))
; check and reset counters
(print
(if (is fizzbuzz 15) (do (= fizzbuzz 0) (= fizz 0) (= buzz 0) "fizzbuzz")
(is fizz 3) (do (= fizz 0) "fizz")
(is buzz 5) (do (= buzz 0) "buzz")
i)))
</syntaxhighlight>
 
=={{header|Fennel}}==
<syntaxhighlight lang="fennel">(for [i 1 100]
(print (if (= (% i 15) 0) :FizzBuzz
(= (% i 3) 0) :Fizz
(= (% i 5) 0) :Buzz
i)))</syntaxhighlight>
Use pattern matching and recursive function:
<syntaxhighlight lang="fennel">(fn fizz-buzz [from to]
(print (match [(% from 3) (% from 5)]
[0 0] :FizzBuzz
[0 _] :Fizz
[_ 0] :Buzz
_ from))
(when (< from to)
(fizz-buzz (+ from 1) to)))
 
(fizz-buzz 1 100)</syntaxhighlight>
Alternative matching pattern:{{trans|D}}
<syntaxhighlight lang="fennel">(for [i 1 100]
(print (match (% i 15)
0 :FizzBuzz
(where (or 3 6 9 12)) :Fizz
(where (or 5 10) :Buzz
_ i)))</syntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="focal">01.10 FOR I=1,100; DO 2.0
01.20 QUIT
 
Line 2,524 ⟶ 4,346:
02.90 TYPE "Buzz" !
02.95 RETURN
02.99 TYPE %3, I, !</langsyntaxhighlight>
 
=={{header|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</syntaxhighlight>
{{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>
 
=={{header|Fish}}==
See [[FizzBuzz/EsoLang#Fish]]
 
=={{header|Forth}}==
===table-driven===
<langsyntaxhighlight lang="forth">: fizz ( n -- ) drop ." Fizz" ;
: buzz ( n -- ) drop ." Buzz" ;
: fb ( n -- ) drop ." FizzBuzz" ;
Line 2,538 ⟶ 4,369:
' fizz , ' . , ' . ,
' fizz , ' buzz , ' . ,
' fizz , ' . , ' . ,</langsyntaxhighlight>
===or the classic approach===
<langsyntaxhighlight lang="forth">: .fizzbuzz ( n -- )
0 pad c!
dup 3 mod 0= if s" Fizz" pad place then
Line 2,548 ⟶ 4,379:
: zz ( n -- )
1+ 1 do i .fizzbuzz cr loop ;
100 zz</langsyntaxhighlight>
===the well factored approach===
SYNONYM is a Forth200x word.
 
<langsyntaxhighlight lang="forth">SYNONYM NOT INVERT \ Bitwise boolean not
 
: Fizz? ( n -- ? ) 3 MOD 0= DUP IF ." Fizz" THEN ;
Line 2,560 ⟶ 4,391:
101 1 DO CR I DUP Fizz? OVER Buzz? OR NOT ?print LOOP ;
 
FizzBuzz</langsyntaxhighlight>
===the unrolled approach===
<langsyntaxhighlight lang="forth">: n ( n -- n+1 ) dup . 1+ ;
: f ( n -- n+1 ) ." Fizz " 1+ ;
: b ( n -- n+1 ) ." Buzz " 1+ ;
Line 2,569 ⟶ 4,400:
: fb15 ( n -- n+15 ) fb10 n f n n fb ;
: fb100 ( n -- n+100 ) fb15 fb15 fb15 fb15 fb15 fb15 fb10 ;
: .fizzbuzz ( -- ) 1 fb100 drop ;</langsyntaxhighlight>
 
=={{header|Fortran}}==
In ANSI FORTRAN 77 or later use structured IF-THEN-ELSE (example uses some ISO Fortran 90 features):
<langsyntaxhighlight lang="fortran">program fizzbuzz_if
integer :: i
Line 2,583 ⟶ 4,414:
end if
end do
end program fizzbuzz_if</langsyntaxhighlight>
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.
<langsyntaxhighlight lang="fortran">program FizzBuzz
implicit none
integer :: i = 1
Line 2,596 ⟶ 4,427:
end do
end program FizzBuzz
</syntaxhighlight>
</lang>
In ISO Fortran 90 or later use SELECT-CASE statement:
<langsyntaxhighlight lang="fortran">program fizzbuzz_select
integer :: i
Line 2,609 ⟶ 4,440:
end select
end do
end program fizzbuzz_select</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
See [[FizzBuzz/Basic]]
 
=={{header|Frege}}==
<langsyntaxhighlight Fregelang="frege">gen n word = cycle (take (n - 1) (repeat "") ++ [word])
pattern = zipWith (++) (gen 3 "fizz") (gen 5 "buzz")
fizzbuzz = zipWith combine pattern [1..] where
Line 2,618 ⟶ 4,452:
then show number
else word
show $ take 100 fizzbuzz</langsyntaxhighlight>
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">for i = 1 to 100
{
flag = false
Line 2,640 ⟶ 4,474:
 
println[]
}</langsyntaxhighlight>
 
=={{header|FutureBasic}}==
<langsyntaxhighlight lang="futurebasic">include "NSLog.incl"
include "ConsoleWindow"
 
dim as shortlong fizz, buzz, i
dim as Str15 s
 
for i = 1 to 100
fizz = (i mod 3 )
buzz = (i mod 5 )
if fizz + buzz == 0 then NSLog(@"FizzBuzz") : continue
if (i)
if fizz + buzz == 0 then print i; NSLog(@".", "FizzBuzzFizz") : exit ifcontinue
if fizzbuzz == 0 then print i; NSLog(@".", "FizzBuzz") : exit ifcontinue
NSLog(@"%ld",i)
if buzz == 0 then print i; ".", "Buzz" : exit if
print i
end if
next i
 
HandleEvents</syntaxhighlight>
</lang>
 
Output:
<pre>
1
2
Fizz
3. Fizz
4
Buzz
5. Buzz
Fizz
6. Fizz
7
8
Fizz
9. Fizz
Buzz
10. Buzz
11
Fizz
12. Fizz
13
14
15. FizzBuzz
16
17
Fizz
18. Fizz
19
Buzz
20. Buzz
Fizz
21. Fizz
22
23
Fizz
24. Fizz
Buzz
25. Buzz
26
Fizz
27. Fizz
28
29
30. FizzBuzz
31
32
Fizz
33. Fizz
34
Buzz
35. Buzz
Fizz
36. Fizz
37
38
Fizz
39. Fizz
Buzz
40. Buzz
41
Fizz
42. Fizz
43
44
45. FizzBuzz
46
47
Fizz
48. Fizz
49
Buzz
50. Buzz
Fizz
51. Fizz
52
53
Fizz
54. Fizz
Buzz
55. Buzz
56
Fizz
57. Fizz
58
59
60. FizzBuzz
61
62
Fizz
63. Fizz
64
Buzz
65. Buzz
Fizz
66. Fizz
67
68
Fizz
69. Fizz
Buzz
70. Buzz
71
Fizz
72. Fizz
73
74
75. FizzBuzz
76
77
Fizz
78. Fizz
79
Buzz
80. Buzz
Fizz
81. Fizz
82
83
Fizz
84. Fizz
Buzz
85. Buzz
86
Fizz
87. Fizz
88
89
90. FizzBuzz
91
92
Fizz
93. Fizz
94
Buzz
95. Buzz
Fizz
96. Fizz
97
98
Fizz
99. Fizz
Buzz
100. Buzz
</pre>
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/FizzBuzz}}
 
'''Solution'''
 
[[File:Fōrmulæ - FizzBuzz 01.png]]
 
[[File:Fōrmulæ - FizzBuzz 01a.png]]
 
[[File:Fōrmulæ - FizzBuzz 02.png]]
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=efbe83377a1eabe475d8eba13965cfde Click this link to run this code]'''
<langsyntaxhighlight lang="gambas">Public Sub Main()
Dim siCount As Short
Dim sText As String
Line 2,780 ⟶ 4,622:
Next
 
End</langsyntaxhighlight>
Output:
<pre>
Line 2,886 ⟶ 4,728:
 
=={{header|GAP}}==
<langsyntaxhighlight lang="gap">FizzBuzz := function()
local i;
for i in [1 .. 100] do
Line 2,899 ⟶ 4,741:
fi;
od;
end;</langsyntaxhighlight>
 
=={{header|GDScript}}==
<syntaxhighlight lang="gdscript">
extends Node
 
func _ready():
for i in range(1, 101):
if i % 15 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)
 
get_tree().quit()
</syntaxhighlight>
 
=={{header|Genyris}}==
<syntaxhighlight lang="genyris">
<lang Genyris>
@prefix u "http://www.genyris.org/lang/utilities#"
 
Line 2,923 ⟶ 4,784:
fb
 
</syntaxhighlight>
</lang>
 
=={{header|GFA Basic}}==
 
<syntaxhighlight lang="text">
' Fizz Buzz
'
Line 2,940 ⟶ 4,802:
ENDIF
NEXT i%
</syntaxhighlight>
</lang>
 
=={{header|Gleam}}==
 
<syntaxhighlight lang="text">import gleam/int
import gleam/io
import gleam/iterator
 
pub fn main() {
iterator.range(1, 101)
|> iterator.map(to_fizzbuzz)
|> iterator.map(io.println)
|> iterator.run
}
 
fn to_fizzbuzz(n: Int) -> String {
case n % 3, n % 5 {
0, 0 -> "FizzBuzz"
0, _ -> "Fizz"
_, 0 -> "Buzz"
_, _ -> int.to_string(n)
}
}</syntaxhighlight>
 
=={{header|Go}}==
===switch/case approach===
<lang go>package main
<syntaxhighlight lang="go">package main
 
import "fmt"
Line 2,960 ⟶ 4,845:
}
}
}</langsyntaxhighlight>
===map approach===
<syntaxhighlight lang="go">package main
 
import "fmt"
 
func main() {
for i := 1; i <= 100; i++ {
fmt.Println(map[bool]map[bool]interface{}{
false: {false: i, true: "Fizz"}, true: {false: "Buzz", true: "FizzBuzz"},
}[i%5 == 0][i%3 == 0])
}
}</syntaxhighlight>
 
=={{header|Golfscript}}==
<syntaxhighlight lang="golfscript">100,{)6,{.(&},{1$1$%{;}{4*35+6875*25base{90\-}%}if}%\or}%n*</syntaxhighlight>
 
=={{header|Golo}}==
<langsyntaxhighlight lang="golo">module FizzBuzz
 
augment java.lang.Integer {
Line 2,979 ⟶ 4,879:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Gosu}}==
<langsyntaxhighlight lang="gosu">for (i in 1..100) {
if (i % 3 == 0 && i % 5 == 0) {
Line 3,002 ⟶ 4,902:
print(i)
}</langsyntaxhighlight>
One liner version (I added new lines to better readability but when you omit them it's one liner):
<langsyntaxhighlight lang="gosu">// note that compiler reports error (I don't know why) but still it's working
for (i in 1..100) {
print(i % 5 == 0 ? i % 3 == 0 ? "FizzBuzz" : "Buzz" : i % 3 == 0 ? "Fizz" : i)
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">1.upto(100) { i -> println "${i % 3 ? '' : 'Fizz'}${i % 5 ? '' : 'Buzz'}" ?: i }</langsyntaxhighlight>
 
=={{header|GW-BASIC}}==
See [[FizzBuzz/Basic]]
 
=={{header|Hare}}==
<syntaxhighlight lang="hare">
use fmt;
 
export fn main() void = {
for (let i = 1z; i <= 100; i += 1) {
fmt::println(
if (i % 15 == 0) "FizzBuzz"
else if (i % 3 == 0) "Fizz"
else if (i % 5 == 0) "Buzz"
else i
)!;
};
};
</syntaxhighlight>
 
=={{header|Haskell}}==
Variant directly implementing the specification:
<syntaxhighlight lang ="haskell">mainfizzbuzz =:: mapM_Int (putStrLn . fizzbuzz)-> [1..100]String
 
fizzbuzz x
| x `mod`f 15 == 0 = "FizzBuzz"
| x `mod` f 3 == 0 = "Fizz"
| x `mod` f 5 == 0 = "Buzz"
| otherwise = show x</lang>
where
f = (0 ==) . rem x
 
main :: IO ()
<lang haskell>main = putStr $ concat $ map fizzbuzz [1..100]
main = mapM_ (putStrLn . fizzbuzz) [1 .. 100]</syntaxhighlight>
 
<syntaxhighlight lang="haskell">fizzbuzz :: Int -> String
fizzbuzz n =
'\n' :
"\n" ++ if null (fizz++buzz) then show n else fizz++buzz
if null (fizz ++ buzz)
where fizz = if mod n 3 == 0 then "Fizz" else ""
then show n
buzz = if mod n 5 == 0 then "Buzz" else ""</lang>
else fizz ++ buzz
where
fizz =
if mod n 3 == 0
then "Fizz"
else ""
buzz =
if mod n 5 == 0
then "Buzz"
else ""
 
main :: IO ()
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].
<langsyntaxhighlight lang="haskell">main = mapM_ (putStrLn . fizzbuzz) [1..100]
 
fizzbuzz n =
Line 3,045 ⟶ 4,977:
 
fizz = "Fizz"
buzz = "Buzz"</langsyntaxhighlight>
Alternate implementation using lazy infinite lists and avoiding use of "mod":
<langsyntaxhighlight 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
 
fizz_buzz_list = zipWith (++) (cycle ["","","Fizz"]) (cycle ["","","","","Buzz"])</langsyntaxhighlight>
 
Or in terms (still without '''mod''' or '''rem''') of an applicative '''ZipList''':
<syntaxhighlight lang="haskell">import Control.Applicative ( ZipList(ZipList, getZipList) )
 
fizzBuzz :: [String]
fizzBuzz =
getZipList $ go <$>
ZipList (cycle $ replicate 2 [] <> ["fizz"]) <*>
ZipList (cycle $ replicate 4 [] <> ["buzz"]) <*>
ZipList (show <$> [1 ..])
 
go :: String -> String -> String -> String
go f b n
| null f && null b = n
| otherwise = f <> b
 
 
main :: IO ()
main = mapM_ putStrLn $ take 100 fizzBuzz</syntaxhighlight>
 
or using an applicative test:
 
<syntaxhighlight lang="haskell">import Data.Bool (bool)
 
fizzBuzz :: [String]
fizzBuzz =
let fb n k = cycle $ replicate (pred n) [] <> [k]
in zipWith
(flip . bool <*> null)
(zipWith (<>) (fb 3 "fizz") (fb 5 "buzz"))
(show <$> [1 ..])
 
main :: IO ()
main = mapM_ putStrLn $ take 100 fizzBuzz
</syntaxhighlight>
 
Using heavy artillery (needs the mtl package):
<langsyntaxhighlight lang="haskell">
import Control.Monad.State
import Control.Monad.Trans
Line 3,065 ⟶ 5,033:
when (x `mod` 5 == 0) $ tell "Buzz" >> put False
get >>= (flip when $ tell $ show x)
tell "\n"</langsyntaxhighlight>
Using guards plus where.
<langsyntaxhighlight lang="haskell">fizzBuzz :: (Integral a) => a -> String
fizzBuzz i
| fizz && buzz = "FizzBuzz"
Line 3,076 ⟶ 5,044:
buzz = i `mod` 5 == 0
 
main = mapM_ (putStrLn . fizzBuzz) [1..100]</langsyntaxhighlight>
 
An elegant solution exploiting monoidal and applicative properties of functions:
<langsyntaxhighlight lang="haskell">import Data.Monoid
 
fizzbuzz = max
Line 3,090 ⟶ 5,058:
divisibleBy n x = x `mod` n == 0
 
main = mapM_ (putStrLn . fizzbuzz) [1..100]</langsyntaxhighlight>
 
And pattern matching approach:
<syntaxhighlight lang="haskell">fizzbuzz n = case (rem n 3, rem n 5) of
(0, 0) -> "FizzBuzz"
(0, _) -> "Fizz"
(_, 0) -> "Buzz"
(_, _) -> show n
 
main = mapM_ (putStrLn . fizzbuzz) [1..100]</syntaxhighlight>
 
Generalised solution:
<syntaxhighlight lang="haskell">wordthing :: [(Int, String)] -> Int -> String
wordthing lst n =
if matches == [] then
show n
else
concat $ map snd matches
where matches = filter (\x -> n `mod` (fst x) == 0) lst
 
fizzbuzz :: Int -> String
fizzbuzz = wordthing [(3, "Fizz"), (5, "Buzz")]
 
main = do
mapM_ (putStrLn . fizzbuzz) [1..100]</syntaxhighlight>
 
=={{header|hexiscript}}==
<syntaxhighlight lang="hexiscript">for let i 1; i <= 100; i++
if i % 3 = 0 && i % 5 = 0; println "FizzBuzz"
elif i % 3 = 0; println "Fizz"
elif i % 5 = 0; println "Buzz"
else println i; endif
endfor</syntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">DO i = 1, 100
IF( MOD(i, 15) == 0 ) THEN
WRITE() "FizzBuzz"
Line 3,103 ⟶ 5,103:
WRITE() i
ENDIF
ENDDO</langsyntaxhighlight>
Alternatively:
<langsyntaxhighlight lang="hicest">CHARACTER string*8
 
DO i = 1, 100
Line 3,113 ⟶ 5,113:
IF( string == " ") WRITE(Text=string) i
WRITE() string
ENDDO</langsyntaxhighlight>
 
=={{header|HolyC}}==
<langsyntaxhighlight lang="holyc">U8 i;
for (i = 1; i <= 100; i++) {
if (!(i % 15))
Line 3,127 ⟶ 5,127:
Print("%d", i);
Print("\n");
}</langsyntaxhighlight>
 
=={{header|Hoon}}==
<langsyntaxhighlight Hoonlang="hoon">:- %say
|= [^ ~ ~]
:- %noun
Line 3,140 ⟶ 5,140:
[& |] "Fizz"
[| &] "Buzz"
==</langsyntaxhighlight>
 
=={{header|Huginn}}==
<syntaxhighlight lang="huginn">import Algorithms as algo;
<lang huginn>
import Algorithms as algo;
 
main( argv_ ) {
Line 3,166 ⟶ 5,165:
}
return ( 0 );
}</langsyntaxhighlight>
 
=={{header|Hy}}==
 
<langsyntaxhighlight lang="lisp">(for [i (range 1 101)] (print (cond
[(not (% i 15)) "FizzBuzz"]
[(not (% i 5)) "Buzz"]
[(not (% i 3)) "Fizz"]
[True i])))</langsyntaxhighlight>
 
=={{header|Ii}}==
<langsyntaxhighlight lang="i">software {
for ieach over [1, to 100]
if i mod% 15 = 0
print("FizzBuzz")
elseifelse if i mod% 3 = 0
print("Fizz")
elseifelse if i mod% 5 = 0
print("Buzz")
else
Line 3,189 ⟶ 5,188:
end
end
}</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight lang="icon"># straight-forward modulo tester
procedure main()
every i := 1 to 100 do
Line 3,203 ⟶ 5,202:
else
write(i)
end</langsyntaxhighlight>
<langsyntaxhighlight lang="icon"># idiomatic modulo tester, 1st alternative
procedure main()
every i := 1 to 100 do
write((i % 15 = 0 & "FizzBuzz") | (i % 5 = 0 & "Buzz") | (i % 3 = 0 & "Fizz") | i)
end</langsyntaxhighlight>
<langsyntaxhighlight lang="icon"># idiomatic modulo tester, 2nd alternative
procedure main()
every i := 1 to 100 do
Line 3,218 ⟶ 5,217:
default: i
})
end</langsyntaxhighlight>
<langsyntaxhighlight lang="icon"># straight-forward buffer builder
procedure main()
every i := 1 to 100 do {
Line 3,231 ⟶ 5,230:
write(s)
}
end</langsyntaxhighlight>
<langsyntaxhighlight lang="icon"># idiomatic buffer builder, 1st alternative
procedure main()
every i := 1 to 100 do
write("" ~== (if i % 3 = 0 then "Fizz" else "") || (if i % 5 == 0 then "Buzz" else "") | i)
end</langsyntaxhighlight>
<langsyntaxhighlight lang="icon"># idiomatic buffer builder, 2nd alternative
procedure main()
every i := 1 to 100 do {
Line 3,244 ⟶ 5,243:
write(("" ~= s) | i)
}
end</langsyntaxhighlight>
 
=={{header|Idris}}==
<langsyntaxhighlight lang="idris">partial
fizzBuzz : Nat -> String
fizzBuzz n = if (n `modNat` 15) == 0 then "FizzBuzz"
Line 3,255 ⟶ 5,254:
 
main : IO ()
main = sequence_ $ map (putStrLn . fizzBuzz) [1..100]</langsyntaxhighlight>
 
=={{header|Inform 6}}==
<langsyntaxhighlight lang="inform6">[ Main i;
for (i = 1: i <= 100: i++) {
if (i % 3 == 0)
{
if(i % 3 == 0) print "Fizz";
if (i % 5 == 0) print "Buzz";
if(i % 3 ~= 0 && i % 5 ~= 0) print i"Buzz";
if (i % 3 ~= 0 && i % 5 ~= 0)
print i;
 
print "^";
}
];</langsyntaxhighlight>
 
=={{header|Inform 7}}==
Line 3,273 ⟶ 5,274:
(Does not work in the current version of Inform 7)
 
<langsyntaxhighlight lang="inform7">Home is a room.
 
When play begins:
Line 3,286 ⟶ 5,287:
if printed is false, say N;
say ".";
end the story.</langsyntaxhighlight>
 
(Version which is less "programmy", and more in the natural English style of interactive fiction.)
 
<langsyntaxhighlight lang="inform7">The space is a room. An item is a kind of thing. In the space are 100 items.
 
To say the name:
Line 3,305 ⟶ 5,306:
end if.
When play begins: count. Use no scoring.</langsyntaxhighlight>
 
=={{header|Insitux}}==
<syntaxhighlight lang="insitux">(function fizzbuzz n
(match (map (rem n) [3 5])
[0 0] "FizzBuzz"
[0 _] "Fizz"
[_ 0] "Buzz"
n))
 
(loop 100 i
(-> i inc fizzbuzz print))</syntaxhighlight>
 
=={{header|Io}}==
Here's one way to do it:
<langsyntaxhighlight lang="io">for(a,1,100,
if(a % 15 == 0) then(
"FizzBuzz" println
Line 3,319 ⟶ 5,331:
a println
)
)</langsyntaxhighlight>
And here's a port of the Ruby version, which I personally prefer:
<langsyntaxhighlight lang="io">a := 0; b := 0
for(n, 1, 100,
if(a = (n % 3) == 0, "Fizz" print);
Line 3,327 ⟶ 5,339:
if(a not and b not, n print);
"\n" print
)</langsyntaxhighlight>
And here is another more idiomatic version:
<langsyntaxhighlight Iolang="io">for (n, 1, 100,
fb := list (
if (n % 3 == 0, "Fizz"),
Line 3,335 ⟶ 5,347:
if (fb isEmpty, n, fb join) println
)</langsyntaxhighlight>
 
=={{header|Ioke}}==
<langsyntaxhighlight lang="ioke">(1..100) each(x,
cond(
(x % 15) zero?, "FizzBuzz" println,
Line 3,344 ⟶ 5,356:
(x % 5) zero?, "Buzz" println
)
)</langsyntaxhighlight>
 
=={{header|Iptscrae}}==
<langsyntaxhighlight lang="iptscrae">; FizzBuzz in Iptscrae
1 a =
{
Line 3,356 ⟶ 5,368:
a ++
}
{ a 100 <= } WHILE</langsyntaxhighlight>
 
=={{header|IS-BASIC}}==
See [[FizzBuzz/Basic]]
 
=={{header|J}}==
 
Perhaps the most concise approach would be [https://jsoftware.github.io/j-playground/bin/html/emj.html#code=%3E((2%23.3%20q%3A15%26%2B.)%7B(%7C.(%3B~%2C%26%3B)%3B%3A'Fizz%20Buzz')%3B~%22%3A)%26%3E1%2Bi.100 >((2#.3 q:15&amp;+.){(|.(;~,&amp;;);:'Fizz Buzz');~":)&amp;&gt;1+i.100]
 
(The above is a live link to a browser based implementation of fizzbuzz in J. To see how this expression works, remove the leading > leaving items in boxes rather than on lines by themselves. And, then, replace the { with ; which means that instead of using the left argument to select (index) from a list of boxes, the left argument is appended in a box to the left of those boxes. Perhaps also replace the 100 with 20 to shrink the result size. If you remove the 1+i.20 (or 1+i.100) entirely, that would display as the verb (function) which is applied to each number.)
 
Other approaches are possible:
 
Solution _1: Using agenda (@.) as a switch:
<syntaxhighlight lang="j">
<lang j>
classify =: +/@(1 2 * 0 = 3 5&|~)
(":@]`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_) @. classify "0) >:i.100
</syntaxhighlight>
</lang>
Solution 0
<langsyntaxhighlight lang="j">> }. (<'FizzBuzz') (I.0=15|n)} (<'Buzz') (I.0=5|n)} (<'Fizz') (I.0=3|n)} ":&.> n=: i.101</langsyntaxhighlight>
Solution 1
<langsyntaxhighlight lang="j">Fizz=: 'Fizz' #~ 0 = 3&|
Buzz=: 'Buzz' #~ 0 = 5&|
FizzBuzz=: ": [^:('' -: ]) Fizz,Buzz
 
FizzBuzz"0 >: i.100</langsyntaxhighlight>
Solution 2 (has taste of table-driven template programming)
<langsyntaxhighlight lang="j">CRT0=: 2 : ' (, 0 = +./)@(0 = m | ]) ;@# n , <@": '
NB. Rather (, 0 = +./) than (, +:/) because designed for
NB. 3 5 7 CRT0 (;:'Chinese Remainder Period') "0 >: i. */3 5 7
FizzBuzz=: 3 5 CRT0 (;:'Fizz Buzz')
 
FizzBuzz"0 >: i.100</langsyntaxhighlight>
Solution 3 (depends on an obsolete feature of @ in f`g`h@p)
<langsyntaxhighlight lang="j">'`f b fb' =: ('Fizz'"_) ` ('Buzz'"_) ` (f , b)
'`cm3 cm5 cm15'=: (3&|) ` (5&|) ` (15&|) (0&=@)
FizzBuzz=: ": ` f @. cm3 ` b @. cm5 ` fb @. cm15 NB. also:
FizzBuzz=: ": ` f @. cm3 ` b @. cm5 ` (f,b) @. (cm3 *. cm5)
 
FizzBuzz"0 >: i.100</langsyntaxhighlight>
 
Solution 4 (relatively concise):
 
<langsyntaxhighlight Jlang="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...</langsyntaxhighlight>
 
Here's some intermediate results for subexpressions of this last version (but with a shorter list of numbers):
 
<langsyntaxhighlight Jlang="j"> i.10
0 1 2 3 4 5 6 7 8 9
(3 5 |/ ])i.10
Line 3,429 ⟶ 5,451:
└─┴─┴────┴─┴────┴────┴─┴─┴────┘
;:inv}.(":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
1 2 Fizz 4 Buzz Fizz 7 8 Fizz</langsyntaxhighlight>
 
=={{header|Janet}}==
<syntaxhighlight lang="janet">
(loop [i :range [1 101]
:let [fizz (zero? (% i 3))
buzz (zero? (% i 5))]]
(print (cond
(and fizz buzz) "fizzbuzz"
fizz "fizz"
buzz "buzz"
i)))
</syntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
See [[FizzBuzz/Java]]
public class FizzBuzz {
public static void main(String[] args) {
for (int number = 1; number <= 100; number++) {
if (number % 15 == 0) {
System.out.println("FizzBuzz");
} else if (number % 3 == 0) {
System.out.println("Fizz");
} else if (number % 5 == 0) {
System.out.println("Buzz");
} else {
System.out.println(number);
}
}
}
}
</syntaxhighlight>
'''Or: '''
<syntaxhighlight lang="java">
public class FizzBuzz {
public static void main(String[] args) {
int number = 1;
while (number <= 100) {
if (number % 15 == 0) {
System.out.println("FizzBuzz");
} else if (number % 3 == 0) {
System.out.println("Fizz");
} else if (number % 5 == 0) {
System.out.println("Buzz");
} else {
System.out.println(number);
}
number++;
}
}
}
</syntaxhighlight>
'''Or: '''
<syntaxhighlight lang="java">
public class FizzBuzz {
public static void main(String[] args) {
int number = 1;
while (number <= 100) {
System.out.println(number % 15 == 0 ? "FizzBuzz" : number % 3 == 0 ? "Fizz" : number % 5 == 0 ? "Buzz" : number);
number++;
}
}
}
</syntaxhighlight>
'''Or: '''
<syntaxhighlight lang="java">
import java.util.stream.IntStream;
class FizzBuzzJdk12 {
public static void main(String[] args) {
IntStream.range(1,101)
.mapToObj(i->switch (i%15) {
case 0 -> "FizzBuzz";
case 3, 6, 9, 12 -> "Fizz";
case 5, 10 -> "Buzz";
default -> Integer.toString(i);
})
.forEach(System.out::println)
;
}
}
</syntaxhighlight>
'''Or: '''
<syntaxhighlight lang="java">
import java.util.stream.IntStream;
 
class FizzBuzzJdk12 {
static final int FIZZ_FLAG = 0x8000_0000;
static final int BUZZ_FLAG = 0x4000_0000;
static final int FIZZ_BUZZ_FLAG = FIZZ_FLAG|BUZZ_FLAG;
static final int[] FLAGS = new int[] {
FIZZ_BUZZ_FLAG|0, 1, 2, FIZZ_FLAG|3, 4,
BUZZ_FLAG|5, FIZZ_FLAG|6, 7, 8, FIZZ_FLAG|9,
BUZZ_FLAG|10, 11, FIZZ_FLAG|12, 13, 14
};
public static void main(String[] args) {
IntStream.iterate(0,i->++i)
.flatMap(i -> IntStream.range(0,15).map(j->FLAGS[j]+15*i))
.mapToObj(
// JDK12 switch expression ...
n-> switch(n & FIZZ_BUZZ_FLAG) {
case FIZZ_BUZZ_FLAG -> "fizzbuzz";
case FIZZ_FLAG -> "fizz";
case BUZZ_FLAG -> "buzz";
default -> Integer.toString(~FIZZ_BUZZ_FLAG & n);
}
)
.skip(1)
.limit(100)
.forEach(System.out::println)
;
}
}
</syntaxhighlight>
 
=={{header|JavaScript}}==
Line 3,438 ⟶ 5,569:
===ES5===
 
<langsyntaxhighlight lang="javascript">var fizzBuzz = function () {
var i, output;
for (i = 1; i < 101; i += 1) {
Line 3,446 ⟶ 5,577:
console.log(output || i);//empty string is false, so we short-circuit
}
};</langsyntaxhighlight>
 
Alternate version with ghetto pattern matching
<langsyntaxhighlight lang="javascript">for (var i = 1; i <= 100; i++) {
console.log({
truefalse: 'Fizz',
Line 3,455 ⟶ 5,586:
truetrue: 'FizzBuzz'
}[(i%3==0) + '' + (i%5==0)] || i)
}</langsyntaxhighlight>
 
Or very tersely:
<langsyntaxhighlight lang="javascript">for(i=1;i<101;i++)console.log((x=(i%3?'':'Fizz')+(i%5?'':'Buzz'))?x:i);</langsyntaxhighlight>
 
Or with even less characters:
<langsyntaxhighlight lang="javascript">for(i=1;i<101;i++)console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)</langsyntaxhighlight>
 
Or, in a more functional style, without mutations
<langsyntaxhighlight lang="javascript">(function rng(i) {
return i ? rng(i - 1).concat(i) : []
})(100).map(
Line 3,474 ⟶ 5,605:
)
}
).join(' ')</langsyntaxhighlight>
 
===ES6===
<langsyntaxhighlight JavaScriptlang="javascript">(() => {
 
// FIZZBUZZ --------------------------------------------------------------
Line 3,512 ⟶ 5,643:
map(fizzBuzz, enumFromTo(1, 100))
);
})();</langsyntaxhighlight>
 
A functional implementation:
 
<syntaxhighlight lang="javascript">const factors = [[3, 'Fizz'], [5, 'Buzz']]
const fizzBuzz = num => factors.map(([factor,text]) => (num % factor)?'':text).join('') || num
const range1 = x => [...Array(x+1).keys()].slice(1)
const outputs = range1(100).map(fizzBuzz)
 
console.log(outputs.join('\n'))</syntaxhighlight>
 
 
Or composing generic functions, and without use of modulo (or other) numeric tests:
{{Trans|Python}}
{{Trans|Haskell}}
<syntaxhighlight lang="javascript">(() => {
'use strict';
 
// main :: IO ()
const main = () => {
 
// FIZZBUZZ ---------------------------------------
 
// fizzBuzz :: Generator [String]
const fizzBuzz = () => {
const fb = n => k => cycle(
replicate(n - 1)('').concat(k)
);
return zipWith(
liftA2(flip)(bool)(isNull)
)(
zipWith(append)(fb(3)('fizz'))(fb(5)('buzz'))
)(fmap(str)(enumFrom(1)));
};
 
// TEST -------------------------------------------
console.log(
unlines(
take(100)(
fizzBuzz()
)
)
);
};
 
// GENERIC FUNCTIONS ----------------------------------
 
// Just :: a -> Maybe a
const Just = x => ({
type: 'Maybe',
Nothing: false,
Just: x
});
 
// Nothing :: Maybe a
const Nothing = () => ({
type: 'Maybe',
Nothing: true,
});
 
// Tuple (,) :: a -> b -> (a, b)
const Tuple = a => b => ({
type: 'Tuple',
'0': a,
'1': b,
length: 2
});
 
// append (++) :: [a] -> [a] -> [a]
// append (++) :: String -> String -> String
const append = xs => ys => xs.concat(ys);
 
// bool :: a -> a -> Bool -> a
const bool = f => t => p =>
p ? t : f;
 
// cycle :: [a] -> Generator [a]
function* cycle(xs) {
const lng = xs.length;
let i = 0;
while (true) {
yield(xs[i])
i = (1 + i) % lng;
}
}
 
// enumFrom :: Int => Int -> [Int]
function* enumFrom(x) {
let v = x;
while (true) {
yield v;
v = 1 + v;
}
}
 
// flip :: (a -> b -> c) -> b -> a -> c
const flip = f =>
x => y => f(y)(x);
 
// fmap <$> :: (a -> b) -> Gen [a] -> Gen [b]
const fmap = f =>
function*(gen) {
let v = take(1)(gen);
while (0 < v.length) {
yield(f(v[0]))
v = take(1)(gen)
}
};
 
// fst :: (a, b) -> a
const fst = tpl => tpl[0];
 
// isNull :: [a] -> Bool
// isNull :: String -> Bool
const isNull = xs =>
1 > xs.length;
 
// Returns Infinity over objects without finite length.
// This enables zip and zipWith to choose the shorter
// argument when one is non-finite, like cycle, repeat etc
 
// length :: [a] -> Int
const length = xs =>
(Array.isArray(xs) || 'string' === typeof xs) ? (
xs.length
) : Infinity;
 
// liftA2 :: (a0 -> b -> c) -> (a -> a0) -> (a -> b) -> a -> c
const liftA2 = op => f => g =>
// Lift a binary function to a composition
// over two other functions.
// liftA2 (*) (+ 2) (+ 3) 7 == 90
x => op(f(x))(g(x));
 
// replicate :: Int -> a -> [a]
const replicate = n => x =>
Array.from({
length: n
}, () => x);
 
// snd :: (a, b) -> b
const snd = tpl => tpl[1];
 
// str :: a -> String
const str = x => x.toString();
 
// take :: Int -> [a] -> [a]
// take :: Int -> String -> String
const take = n => xs =>
'GeneratorFunction' !== xs.constructor.constructor.name ? (
xs.slice(0, n)
) : [].concat.apply([], Array.from({
length: n
}, () => {
const x = xs.next();
return x.done ? [] : [x.value];
}));
 
// The first argument is a sample of the type
// allowing the function to make the right mapping
 
// uncons :: [a] -> Maybe (a, [a])
const uncons = xs => {
const lng = length(xs);
return (0 < lng) ? (
lng < Infinity ? (
Just(Tuple(xs[0])(xs.slice(1))) // Finite list
) : (() => {
const nxt = take(1)(xs);
return 0 < nxt.length ? (
Just(Tuple(nxt[0])(xs))
) : Nothing();
})() // Lazy generator
) : Nothing();
};
 
// unlines :: [String] -> String
const unlines = xs => xs.join('\n');
 
// zipWith :: (a -> b -> c) Gen [a] -> Gen [b] -> Gen [c]
const zipWith = f => ga => gb => {
function* go(ma, mb) {
let
a = ma,
b = mb;
while (!a.Nothing && !b.Nothing) {
let
ta = a.Just,
tb = b.Just
yield(f(fst(ta))(fst(tb)));
a = uncons(snd(ta));
b = uncons(snd(tb));
}
}
return go(uncons(ga), uncons(gb));
};
 
// MAIN ---
return main();
})();</syntaxhighlight>
 
=={{header|Joy}}==
The following program first defines a function "oneout", whichthat 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="joy">DEFINE oneout == [[[dup 15 rem 0 =null] "FizzBuzz"] [[dup 3 rem 0 =] "Fizz"] [[dup 5 rem 0 =] "Buzz"] [dup]] cond.
[[ 3 rem null] "Fizz"]
1 [100 <=] [dup one put succ] while.</lang>
[[ 5 rem null] "Buzz"]
[]] cond
[putchars pop] [put] ifstring '\n putch.
 
100 [] [out] primrec.</syntaxhighlight>
 
=={{header|jq}}==
<langsyntaxhighlight lang="jq">range(1;101)
| if . % 15 == 0 then "FizzBuzz"
elif . % 5 == 0 then "Buzz"
elif . % 3 == 0 then "Fizz"
else .
end</langsyntaxhighlight>
 
Another solution:
 
<langsyntaxhighlight lang="jq">range(100) + 1 | [(
(select(. % 3 == 0) | "Fizz"),
(select(. % 5 == 0) | "Buzz")
) // tostring] | join("")
</syntaxhighlight>
</lang>
 
=={{header|Julia}}==
{{works with|Julia|01.68.5}}
 
One basic solution:
<langsyntaxhighlight lang="julia">for i in 1:100
if i % 15 == 0
println("FizzBuzz")
Line 3,549 ⟶ 5,884:
println(i)
end
end</langsyntaxhighlight>
 
Another possible solution:
<langsyntaxhighlight lang="julia">collect(i % 15 == 0 ? "FizzBuzz" : i % 5 == 0 ? "Buzz" : i % 3 == 0 ? "Fizz" : i for i in 1:100) |> println</langsyntaxhighlight>
 
A 3rd possible solution:
<langsyntaxhighlight lang="julia">fb(i::Integer) = "Fizz" ^ (i % 3 == 0) * "Buzz" ^ (i % 5 == 0) * decstring(i) ^ (i % 3 != 0 && i % 5 != 0)
for i in 1:100 println(fb(i)) end</langsyntaxhighlight>
 
A 4th one:
<langsyntaxhighlight lang="julia">println.(map(fb, 1:100))</langsyntaxhighlight>
 
A fifth (DRY, Don't Repeat Yourself) possible solution:
<langsyntaxhighlight lang="julia">for i in 1:100
msg = "Fizz" ^ (i % 3 == 0) * "Buzz" ^ (i % 5 == 0)
println(isempty(msg) ? i : msg)
end</langsyntaxhighlight>
 
=={{header|K}}==
===Solution 0===
<langsyntaxhighlight lang="k">`0:\:{:[0=#a:{,/$(:[0=x!3;"Fizz"];:[0=x!5;"Buzz"])}@x;$x;a]}'1_!101</langsyntaxhighlight>
 
===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' 1+!100
</syntaxhighlight>
</lang>
 
===Solution 2===
<langsyntaxhighlight lang="k">fizzbuzz:{
v:1+!x
i:(&0=)'v!/:3 5 15
Line 3,585 ⟶ 5,920:
@[r;i 2;{"FizzBuzz"}]}
 
`0:$fizzbuzz 100</langsyntaxhighlight>
 
===Solution 3===
For kona: <langsyntaxhighlight lang="k">{,/$(s;x)@~#s:`Fizz`Buzz@&~x!'3 5}'1+!30</langsyntaxhighlight>
For k6 and oK, change <code>x!'3 5</code> to <code>3 5!'x</code>.
 
Line 3,595 ⟶ 5,930:
 
This will only work up to 100 because Kamailio terminates all while loops after 100 iterations.
<langsyntaxhighlight lang="kamailio"># FizzBuzz
log_stderror=yes
loadmodule "pv"
Line 3,614 ⟶ 5,949:
$var(i) = $var(i) + 1;
}
}</langsyntaxhighlight>
 
=={{header|Kaya}}==
<langsyntaxhighlight lang="kaya">// fizzbuzz in Kaya
program fizzbuzz;
 
Line 3,636 ⟶ 5,971:
Void main() {
fizzbuzz(100);
}</langsyntaxhighlight>
 
=={{header|KL1}}==
<syntaxhighlight lang="prolog">
:- module main.
 
main :-
nats(100, Nats),
fizzbuzz(Nats, Output),
display(Output).
 
nats(Max, Out) :-
nats(Max, 1, Out).
nats(Max, Count, Out) :- Count =< Max |
Out = [Count|NewOut],
NewCount := Count + 1,
nats(Max, NewCount, NewOut).
nats(Max, Count, Out) :- Count > Max |
Out = [].
 
fizzbuzz([N|Rest], Out) :- N mod 3 =:= 0, N mod 5 =:= 0 |
Out = ['FizzBuzz' | NewOut],
fizzbuzz(Rest, NewOut).
fizzbuzz([], Out) :-
Out = [].
alternatively.
fizzbuzz([N|Rest], Out) :- N mod 3 =:= 0 |
Out = ['Fizz' | NewOut],
fizzbuzz(Rest, NewOut).
fizzbuzz([N|Rest], Out) :- N mod 5 =:= 0 |
Out = ['Buzz' | NewOut],
fizzbuzz(Rest, NewOut).
alternatively.
fizzbuzz([N|Rest], Out) :-
Out = [N | NewOut],
fizzbuzz(Rest, NewOut).
 
display([Message|Rest]) :-
io:outstream([print(Message), nl]),
display(Rest).
display([]).
</syntaxhighlight>
 
=={{header|Klong}}==
<syntaxhighlight lang="k">
<lang k>
{:[0=x!15;:FizzBuzz:|0=x!5;:Buzz:|0=x!3;:Fizz;x]}'1+!100
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
 
===Imperative solution===
<langsyntaxhighlight lang="scala">fun fizzBuzz() {
for (inumber in 1..100) {
when {println(
iwhen % 15 == 0 -> println("FizzBuzz"){
i number % 315 == 0 -> println("FizzFizzBuzz")
i number % 53 == 0 -> println("BuzzFizz")
else number % 5 == 0 -> println(i)"Buzz"
} else -> number
}
)
}
}</langsyntaxhighlight>
 
===Functional solution 1===
<langsyntaxhighlight lang="scala">fun fizzBuzz1() {
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
Line 3,664 ⟶ 6,042:
 
(1..100).map { fizzBuzz(it) }.map { fizz(it) }.map { buzz(it) }.forEach { println(it) }
}</langsyntaxhighlight>
 
===Functional solution 2===
<langsyntaxhighlight lang="scala">fun fizzBuzz2() {
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
Line 3,677 ⟶ 6,055:
.map { none(it) }
.forEach { println(it) }
}</langsyntaxhighlight>
 
===Short version with mapOf===
<syntaxhighlight lang="scala">
fun fizzBuzz() {
(1..100).forEach { println(mapOf(0 to it, it % 3 to "Fizz", it % 5 to "Buzz", it % 15 to "FizzBuzz")[0]) }
}
</syntaxhighlight>
 
=={{header|KQL}}==
<syntaxhighlight lang="kql">
range i from 1 to 100 step 1
| project Result =
case(
i % 15 == 0, "FizzBuzz",
i % 3 == 0, "Fizz",
i % 5 == 0, "Buzz",
tostring(i)
)
</syntaxhighlight>
 
=={{header|KSI}}==
<syntaxhighlight lang="ksi">
`plain
[1 100] `for pos : n ~
out = []
n `mod 3 == 0 ? out.# = 'Fizz' ;
n `mod 5 == 0 ? out.# = 'Buzz' ;
(out `or n) #write_ln #
;
</syntaxhighlight>
 
=={{header|LabVIEW}}==
{{VI snippet}}<br/>
[[file:LabVIEW_FizzBuzz.png]]
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
1. direct:
 
{S.map
{lambda {:i}
{if {= {% :i 15} 0}
then fizzbuzz
else {if {= {% :i 3} 0}
then fizz
else {if {= {% :i 5} 0}
then buzz
else :i}}}}
{S.serie 1 100}}
-> 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
 
2. via a function
 
{def fizzbuzz
{lambda {:i :n}
{if {> :i :n}
then .
else {if {= {% :i 15} 0}
then fizzbuzz
else {if {= {% :i 3} 0}
then fizz
else {if {= {% :i 5} 0}
then buzz
else :i}}} {fizzbuzz {+ :i 1} :n}
}}}
-> fizzbuzz
 
{fizzbuzz 1 100}
-> same as above.
 
</syntaxhighlight>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang">
$i = 1
while($i <= 100) {
if($i % 15 == 0) {
fn.println(FizzBuzz)
}elif($i % 5 == 0) {
fn.println(Buzz)
}elif($i % 3 == 0) {
fn.println(Fizz)
}else {
fn.println($i)
}
$i += 1
}
</syntaxhighlight>
 
=={{header|langur}}==
<syntaxhighlight lang="langur">for .i of 100 {
writeln switch(0; .i rem 15: "FizzBuzz"; .i rem 5: "Buzz"; .i rem 3: "Fizz"; .i)
}</syntaxhighlight>
 
<syntaxhighlight lang="langur">for .i of 100 {
writeln if(.i div 15: "FizzBuzz"; .i div 5: "Buzz"; .i div 3: "Fizz"; .i)
}</syntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight lang="lasso">with i in generateSeries(1, 100)
select ((#i % 3 == 0 ? 'Fizz' | '') + (#i % 5 == 0 ? 'Buzz' | '') || #i)</langsyntaxhighlight>
 
=={{header|LaTeX}}==
Line 3,691 ⟶ 6,163:
{{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.
<langsyntaxhighlight LaTeXlang="latex">\documentclass{minimal}
\usepackage{ifthen}
\usepackage{intcalc}
 
\newcounter{mycount}
\newboolean{fizzOrBuzz}
 
\newcommand\fizzBuzz[1]{%
\setcounter{mycount}{1}\whiledo{\value{mycount}<#1}
{
\setboolean{fizzOrBuzz}{false}
\ifthenelse{\equal{\intcalcMod{\themycount}{3}}{0}}{\setboolean{fizzOrBuzz}{true}Fizz}{}
\ifthenelse{\equal{\intcalcMod{\themycount}{5}}{0}}{\setboolean{fizzOrBuzz}{true}Buzz}{}
\ifthenelse{\boolean{fizzOrBuzz}}{}{\themycount}
\stepcounter{mycount}
\\
}
}
 
\begin{document}
\fizzBuzz{101}
\end{document}</langsyntaxhighlight>
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">data:
i is number
n is number
 
procedure:
for i from 1 to 101 step 1 do
modulo i by 15 in n
if n is equal to 0 then
display "FizzBuzz" lf
continue
end if
modulo i by 5 in n
if n is equal to 0 then
display "Buzz" lf
continue
end if
modulo i by 3 in n
if n is equal to 0 then
display "Fizz" lf
continue
end if
display i lf
repeat
</syntaxhighlight>
 
=={{header|Lean}}==
 
Lean 4:
 
<syntaxhighlight lang="lean">
def fizz : String :=
"Fizz"
 
def buzz : String :=
"Buzz"
 
def newLine : String :=
"\n"
 
def isDivisibleBy (n : Nat) (m : Nat) : Bool :=
match m with
| 0 => false
| (k + 1) => (n % (k + 1)) = 0
 
def getTerm (n : Nat) : String :=
if (isDivisibleBy n 15) then (fizz ++ buzz)
else if (isDivisibleBy n 3) then fizz
else if (isDivisibleBy n 5) then buzz
else toString (n)
 
def range (a : Nat) (b : Nat) : List (Nat) :=
match b with
| 0 => []
| m + 1 => a :: (range (a + 1) m)
 
def getTerms (n : Nat) : List (String) :=
(range 1 n).map (getTerm)
 
def addNewLine (accum : String) (elem : String) : String :=
accum ++ elem ++ newLine
 
def fizzBuzz : String :=
(getTerms 100).foldl (addNewLine) ("")
 
def main : IO Unit :=
IO.println (fizzBuzz)
 
#eval main
</syntaxhighlight>
 
 
=={{header|Liberty BASIC}}==
See [[FizzBuzz/Basic]]
 
=={{header|LIL}}==
<syntaxhighlight lang="tcl"># fizzbuzz in LIL
for {set i 1} {$i <= 100} {inc i} {
set show ""
if {[expr $i % 3 == 0]} {set show "Fizz"}
if {[expr $i % 5 == 0]} {set show $show"Buzz"}
if {[expr [length $show] == 0]} {set show $i}
print $show
}</syntaxhighlight>
 
{{out}}
<pre>prompt$ lil fizzbuzz.lil | sed -n '1,16p'
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16</pre>
 
=={{header|LiveCode}}==
<langsyntaxhighlight LiveCodelang="livecode">repeat with i = 1 to 100
switch
case i mod 15 = 0
Line 3,733 ⟶ 6,303:
end switch
end repeat
put fizzbuzz</langsyntaxhighlight>
 
=={{header|LiveScript}}==
See: http://livescript.net/blog/fizzbuzzbazz.html
<langsyntaxhighlight LiveScriptlang="livescript">[1 to 100] map -> [k + \zz for k, v of {Fi: 3, Bu: 5} | it % v < 1] * '' || it</langsyntaxhighlight>
 
=={{header|LLVM}}==
<syntaxhighlight lang="llvm">; ModuleID = 'fizzbuzz.c'
; source_filename = "fizzbuzz.c"
; target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
; target triple = "x86_64-pc-windows-msvc19.21.27702"
; This is not strictly LLVM, as it uses the C library function "printf".
; LLVM does not provide a way to print values, so the alternative would be
; to just load the string into memory, and that would be boring.
 
; Additional comments have been inserted, as well as changes made from the output produced by clang such as putting more meaningful labels for the jumps
 
$"\01??_C@_09NODAFEIA@FizzBuzz?6?$AA@" = comdat any
$"\01??_C@_05KEBFOHOF@Fizz?6?$AA@" = comdat any
$"\01??_C@_05JKJENPHA@Buzz?6?$AA@" = comdat any
$"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@" = comdat any
 
;--- String constant defintions
@"\01??_C@_09NODAFEIA@FizzBuzz?6?$AA@" = linkonce_odr unnamed_addr constant [10 x i8] c"FizzBuzz\0A\00", comdat, align 1
@"\01??_C@_05KEBFOHOF@Fizz?6?$AA@" = linkonce_odr unnamed_addr constant [6 x i8] c"Fizz\0A\00", comdat, align 1
@"\01??_C@_05JKJENPHA@Buzz?6?$AA@" = linkonce_odr unnamed_addr constant [6 x i8] c"Buzz\0A\00", comdat, align 1
@"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@" = linkonce_odr unnamed_addr constant [4 x i8] c"%d\0A\00", comdat, align 1
 
;--- The declaration for the external C printf function.
declare i32 @printf(i8*, ...)
 
; Function Attrs: noinline nounwind optnone uwtable
define i32 @main() #0 {
%1 = alloca i32, align 4
store i32 1, i32* %1, align 4
;--- It does not seem like this branch can be removed
br label %loop
 
;--- while (i <= 100)
loop:
%2 = load i32, i32* %1, align 4
%3 = icmp sle i32 %2, 100
br i1 %3, label %divisible_15, label %finished
 
;--- if (i % 15 == 0)
divisible_15:
%4 = load i32, i32* %1, align 4
%5 = srem i32 %4, 15
%6 = icmp eq i32 %5, 0
br i1 %6, label %print_fizzbuzz, label %divisible_3
 
;--- Print 'FizzBuzz'
print_fizzbuzz:
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @"\01??_C@_09NODAFEIA@FizzBuzz?6?$AA@", i32 0, i32 0))
br label %next
 
;--- if (i % 3 == 0)
divisible_3:
%8 = load i32, i32* %1, align 4
%9 = srem i32 %8, 3
%10 = icmp eq i32 %9, 0
br i1 %10, label %print_fizz, label %divisible_5
 
;--- Print 'Fizz'
print_fizz:
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @"\01??_C@_05KEBFOHOF@Fizz?6?$AA@", i32 0, i32 0))
br label %next
 
;--- if (i % 5 == 0)
divisible_5:
%12 = load i32, i32* %1, align 4
%13 = srem i32 %12, 5
%14 = icmp eq i32 %13, 0
br i1 %14, label %print_buzz, label %print_number
 
;--- Print 'Buzz'
print_buzz:
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @"\01??_C@_05JKJENPHA@Buzz?6?$AA@", i32 0, i32 0))
br label %next
 
;--- Print the number
print_number:
%16 = load i32, i32* %1, align 4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@", i32 0, i32 0), i32 %16)
;--- It does not seem like this branch can be removed
br label %next
 
;--- i = i + 1
next:
%18 = load i32, i32* %1, align 4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1, align 4
br label %loop
 
;--- exit main
finished:
ret i32 0
}
 
attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
 
!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}
 
!0 = !{i32 1, !"wchar_size", i32 2}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{!"clang version 6.0.1 (tags/RELEASE_601/final)"}</syntaxhighlight>
 
=={{header|Lobster}}==
<langsyntaxhighlight Lobsterlang="lobster">include "std.lobster"
 
forbias(100, 1) i:
fb := (i % 3 == 0 and "fizz" or "") +
(i % 5 == 0 and "buzz" or "")
print fb.length and fb or "" + i</langsyntaxhighlight>
 
=={{header|Logo}}==
<langsyntaxhighlight lang="logo">to fizzbuzz :n
output cond [ [[equal? 0 modulo :n 15] "FizzBuzz]
[[equal? 0 modulo :n 5] "Buzz]
Line 3,755 ⟶ 6,428:
end
 
repeat 100 [print fizzbuzz #]</langsyntaxhighlight>
"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:
<langsyntaxhighlight lang="logo">to fizzbuzz :n
make "c "
if equal? 0 modulo :n 5 [make "c "Buzz]
Line 3,764 ⟶ 6,437:
end
 
repeat 100 [print fizzbuzz repcount]</langsyntaxhighlight>
Lhogho can use the above code, except that 'modulo' must be replaced with 'remainder'.
 
Line 3,771 ⟶ 6,444:
 
=={{header|LSE}}==
<langsyntaxhighlight LSElang="lse">1* FIZZBUZZ en L.S.E.
10 CHAINE FB
20 FAIRE 45 POUR I_1 JUSQUA 100
Line 3,779 ⟶ 6,452:
50 TERMINER
100 PROCEDURE &MOD(A,B) LOCAL A,B
110 RESULTAT A-B*ENT(A/B)</langsyntaxhighlight>
 
=={{header|Lua}}==
===If/else Ladder===
<langsyntaxhighlight Lualang="lua">for i = 1, 100 do
if i % 15 == 0 then
print("FizzBuzz")
Line 3,793 ⟶ 6,466:
print(i)
end
end</langsyntaxhighlight>
===Concatenation===
<langsyntaxhighlight Lualang="lua">for i = 1, 100 do
output = ""
if i % 3 == 0 then
Line 3,807 ⟶ 6,480:
end
print(output)
end</langsyntaxhighlight>
 
===Quasi bit field===
<langsyntaxhighlight Lualang="lua">word = {"Fizz", "Buzz", "FizzBuzz"}
 
for i = 1, 100 do
print(word[(i % 3 == 0 and 1 or 0) + (i % 5 == 0 and 2 or 0)] or i)
end</langsyntaxhighlight>
 
===Lookup table===
<syntaxhighlight lang="lua">local t = {
[0] = "FizzBuzz",
[3] = "Fizz",
[5] = "Buzz",
[6] = "Fizz",
[9] = "Fizz",
[10] = "Buzz",
[12] = "Fizz"
}
 
for i = 1, 100 do
print(t[i%15] or i)
end</syntaxhighlight>
 
=== Metatable insertion ===
Sets any numeric key to its fizzbuzz value so that fizzbuzz[30] is "fizzbuzz"
<syntaxhighlight lang="lua">local mt = {
__newindex = (function (t, k, v)
if type(k) ~= "number" then rawset(t, k, v)
elseif 0 == (k % 15) then rawset(t, k, "fizzbuzz")
elseif 0 == (k % 5) then rawset(t, k, "fizz")
elseif 0 == (k % 3) then rawset(t, k, "buzz")
else rawset(t, k, k) end
return t[k]
end)
}
 
local fizzbuzz = {}
setmetatable(fizzbuzz, mt)
 
for i=1,100 do fizzbuzz[i] = i end
for i=1,100 do print(fizzbuzz[i]) end
</syntaxhighlight>
 
=== Fast Version without Modulo ===
<syntaxhighlight lang="lua">
#!/usr/bin/env luajit
local to=arg[1] or tonumber(arg[1]) or 100
local CF,CB=3,5
local cf,cb=CF,CB
for i=1,to do
cf,cb=cf-1,cb-1
if cf~=0 and cb~=0 then
io.write(i)
else
if cf==0 then
cf=CF
io.write("Fizz")
end
if cb==0 then
cb=CB
io.write("Buzz")
end
end
io.write(", ")
end
</syntaxhighlight>
 
{{out}}
<pre>
> ./fizzbuzz.lua
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>
 
=={{header|Luck}}==
<langsyntaxhighlight Lucklang="luck">for i in range(1,101) do (
if i%15 == 0 then print("FizzBuzz")
else if i%3 == 0 then print("Fizz")
else if i%5 == 0 then print("Buzz")
else print(i)
)</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
\\ 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
 
\\ Better code
For i=1 to 100 {
Push str$(i,0)+". "+if$(i mod 3=0->"Fizz","")+if$(i mod 5=0->"Buzz","")
If stackitem$()="" then Drop : Continue
Print Letter$
}
 
\\ Far Better Code
For i=1 to 100 {
Printme(if$(i mod 3=0->"Fizz","")+if$(i mod 5=0->"Buzz",""))
}
Print
Sub Printme(a$)
If a$<>"" Then Print a$, else Print i,
End Sub
</syntaxhighlight>
 
=={{header|M4}}==
<langsyntaxhighlight M4lang="m4">define(`for',
`ifelse($#,0,``$0'',
`ifelse(eval($2<=$3),1,
Line 3,834 ⟶ 6,594:
`ifelse(eval(x%3==0),1,Fizz,
`ifelse(eval(x%5==0),1,Buzz,x)')')
')</langsyntaxhighlight>
 
=={{header|MACRO-11}}==
<syntaxhighlight lang="macro11"> .TITLE FIZBUZ
.MCALL .TTYOUT,.EXIT
FIZBUZ::MOV #1,R2 ; COUNTER
MOV #3,R3 ; FIZZ COUNTER
MOV #5,R4 ; BUZZ COUNTER
NUMBER: CLR R5
CHKFIZ: DEC R3
BNE CHKBUZ
MOV #FIZZ,R1
JSR PC,PRSTR
MOV #3,R3
INC R5
CHKBUZ: DEC R4
BNE CHKNUM
MOV #BUZZ,R1
JSR PC,PRSTR
MOV #5,R4
INC R5
CHKNUM: TST R5
BNE NEXNUM
MOV R2,R0
JSR PC,PR0
NEXNUM: MOV #NL,R1
JSR PC,PRSTR
INC R2
CMP R2,#^D100
BLE NUMBER
.EXIT
; STRING DATA
FIZZ: .ASCIZ /FIZZ/
BUZZ: .ASCIZ /BUZZ/
NL: .BYTE 15,12,0
.EVEN
; PRINT NUMBER IN R0 AS DECIMAL
PR0: MOV R2,-(SP)
MOV #4$,R1
1$: MOV #-1,R2
2$: INC R2
SUB #12,R0
BCC 2$
ADD #72,R0
MOVB R0,-(R1)
MOV R2,R0
BNE 1$
3$: MOVB (R1)+,R0
.TTYOUT
BNE 3$
MOV (SP)+,R2
RTS PC
.ASCII /...../
4$: .BYTE 0
; PRINT STRING IN R1
PRSTR: MOVB (R1)+,R0
.TTYOUT
BNE PRSTR
RTS PC
.END FIZBUZ</syntaxhighlight>
 
=={{header|MAD}}==
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
VECTOR VALUES FIZZ = $4HFIZZ*$
VECTOR VALUES BUZZ = $4HBUZZ*$
VECTOR VALUES FIBU = $8HFIZZBUZZ*$
VECTOR VALUES NUM = $I2*$
 
INTERNAL FUNCTION REM.(A,B) = A-(A/B)*B
 
THROUGH LOOP, FOR I = 1, 1, I .G. 100
WHENEVER REM.(I,15).E.0
PRINT FORMAT FIBU
OR WHENEVER REM.(I,5).E.0
PRINT FORMAT BUZZ
OR WHENEVER REM.(I,3).E.0
PRINT FORMAT FIZZ
OTHERWISE
PRINT FORMAT NUM,I
LOOP END OF CONDITIONAL
 
END OF PROGRAM</syntaxhighlight>
 
=={{header|make}}==
{{works with|BSD make}}
{{libheader|jot}}
<langsyntaxhighlight lang="make">MOD3 = 0
MOD5 = 0
ALL != jot 100
Line 3,866 ⟶ 6,707:
. endif
 
.endfor</langsyntaxhighlight>
 
=={{header|Maple}}==
One line:
<langsyntaxhighlight Maplelang="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):</langsyntaxhighlight>
With a fizzbuzz function defined:
<langsyntaxhighlight Maplelang="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;</langsyntaxhighlight>
Using piecewise:
<langsyntaxhighlight Maplelang="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;</langsyntaxhighlight>
Using conventional if/then branches:
<langsyntaxhighlight Maplelang="maple">fizzbuzz3 := proc(n) local r;
r:=map2(modp,n,[3,5]);
if r=[0,0] then "FizzBuzz"
Line 3,885 ⟶ 6,726:
else n fi;
end proc:
for i to 100 do fizzbuzz3(i); od;</langsyntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">Do[Print[Which[Mod[i, 15] == 0, "FizzBuzz", Mod[i, 5] == 0, "Buzz", Mod[i, 3] == 0, "Fizz", True, i]], {i, 100}]</langsyntaxhighlight>
Using rules,
<langsyntaxhighlight Mathematicalang="mathematica">fizz[i_] := Mod[i, 3] == 0
buzz[i_] := Mod[i, 5] == 0
Range[100] /. {i_ /; fizz[i]&&buzz[i] :> "FizzBuzz", \
i_?fizz :> "Fizz", i_?buzz :> "Buzz"}</langsyntaxhighlight>
Using rules, but different approach:
<langsyntaxhighlight Mathematicalang="mathematica">SetAttributes[f,Listable]
f[n_ /; Mod[n, 15] == 0] := "FizzBuzz";
f[n_ /; Mod[n, 3] == 0] := "Fizz";
Line 3,901 ⟶ 6,742:
f[n_] := n;
 
f[Range[100]]</langsyntaxhighlight>
An extendible version using Table
<langsyntaxhighlight Mathematicalang="mathematica">Table[If[# === "", i, #]&@StringJoin[
Table[If[Divisible[i, First@nw], Last@nw, ""],
{nw, {{3, "Fizz"}, {5, "Buzz"}}}]],
{i, 1, 100}]</langsyntaxhighlight>
Another one-liner using Map (the /@ operator shorthand of it) and a pure function with a very readable Which
<langsyntaxhighlight Mathematicalang="mathematica"> Which[ Mod[#,15] == 0, "FizzBuzz", Mod[#, 3] == 0, "Fizz", Mod[#,5]==0, "Buzz", True, #]& /@ Range[1,100] </langsyntaxhighlight>
 
Additional examples using DownValue pattern matching, the first without Mod'ing 15:
<syntaxhighlight lang="mathematica">f[n_] := f[n, Mod[n, {3, 5}]]
f[_, {0, 0}] := "FizzBuzz"
f[_, {0, _}] := "Fizz"
f[_, {_, 0}] := "Buzz"
f[n_, {_, _}] := n
 
f /@ Range[100]</syntaxhighlight>
 
<syntaxhighlight lang="mathematica">f[n_] := f[n, Mod[n, 15]]
f[_, 0] := "FizzBuzz"
 
f[n_, _] := f[n, Mod[n, {3, 5}]]
f[_, {0, _}] := "Fizz"
f[_, {_, 0}] := "Buzz"
f[n_, {_, _}] := n
 
f /@ Range[100]</syntaxhighlight>
 
=={{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).
<langsyntaxhighlight MATLABlang="matlab">function fizzBuzz()
for i = (1:100)
if mod(i,15) == 0
Line 3,925 ⟶ 6,785:
end
fprintf('\n');
end</langsyntaxhighlight>
Here's a more extendible version that uses disp() to print the output:
<langsyntaxhighlight MATLABlang="matlab">function out = fizzbuzzS()
nums = [3, 5];
words = {'fizz', 'buzz'};
Line 3,943 ⟶ 6,803:
end
end
end</langsyntaxhighlight>
 
'''straightforward'''
<syntaxhighlight lang="matlab">
x = string(1:100);
x(3:3:$) = 'Fizz';
x(5:5:$) = 'Buzz';
x(3*5:3*5:$) = 'FizzBuzz'
</syntaxhighlight>
 
=={{header|Maxima}}==
<langsyntaxhighlight lang="maxima">for n:1 thru 100 do
if mod(n, 15) = 0 then disp(sprint("FizzBuzz"), newline())
elseif mod(n, 3) = 0 then disp(sprint("Fizz"), newline())
elseif mod(n,5) = 0 then disp(sprint("Buzz"), newline())
else disp(sprint(n), newline());</langsyntaxhighlight>
 
=={{header|MAXScript}}==
<langsyntaxhighlight lang="maxscript">for i in 1 to 100 do
(
case of
Line 3,962 ⟶ 6,830:
default: (print i)
)
)</langsyntaxhighlight>
 
=={{header|MEL}}==
<langsyntaxhighlight lang="mel">for($i=1; $i<=100; $i++)
{
if($i % 15 == 0)
Line 3,975 ⟶ 6,843:
else
print ($i + "\n");
}</langsyntaxhighlight>
 
=={{header|Mercury}}==
<langsyntaxhighlight lang="mercury">:- module fizzbuzz.
 
:- interface.
 
:- import_module io.
 
:- pred main(io::di, io::uo) is det.
 
:- implementation.
 
:- import_module int, string, bool.
 
Line 4,007 ⟶ 6,870:
:- pred main(int::in, int::in, io::di, io::uo) is det.
main(N, To, !IO) :-
io.write_string(fizzbuzz(N, fizz(N), buzz(N)), !IO), io.nl(!IO),
( N < To -> mainio.nl(N + 1, To, !IO),
; ( if N < To !:IO = !.IO ).</lang>then
main(N + 1, To, !IO)
else
true
).</syntaxhighlight>
 
=={{header|Metafont}}==
<langsyntaxhighlight lang="metafont">for i := 1 upto 100:
message if i mod 15 = 0: "FizzBuzz" &
elseif i mod 3 = 0: "Fizz" &
Line 4,018 ⟶ 6,885:
else: decimal i & fi "";
endfor
end</langsyntaxhighlight>
 
=={{header|Microsoft Small Basic}}==
{{trans|GW-BASIC}}
<langsyntaxhighlight lang="microsoftsmallbasic">
For n = 1 To 100
op = ""
Line 4,037 ⟶ 6,904:
EndIf
EndFor
</syntaxhighlight>
</lang>
 
=={{header|min}}==
{{works with|min|0.19.3}}
<syntaxhighlight lang="min">0 (
succ false :hit
(3 mod 0 ==) ("Fizz" print! true @hit) when
(5 mod 0 ==) ("Buzz" print! true @hit) when
(hit) (print) unless newline
) 100 times</syntaxhighlight>
 
=={{header|Minimal BASIC}}==
See [[FizzBuzz/Basic]]
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">for i in range(1,100)
if i % 15 == 0 then
print "FizzBuzz"
else if i % 3 == 0 then
print "Fizz"
else if i % 5 == 0 then
print "Buzz"
else
print i
end if
end for</syntaxhighlight>
 
=={{header|MIPS Assembly}}==
<langsyntaxhighlight lang="mips">
#################################
# Fizz Buzz #
Line 4,115 ⟶ 7,007:
li $v0,10
syscall
</syntaxhighlight>
</lang>
 
=={{header|Mirah}}==
<langsyntaxhighlight lang="mirah">1.upto(100) do |n|
print "Fizz" if a = ((n % 3) == 0)
print "Buzz" if b = ((n % 5) == 0)
print n unless (a || b)
print "\n"
end</langsyntaxhighlight>
 
A little more straight forward:
<langsyntaxhighlight lang="mirah">1.upto(100) do |n|
if (n % 15) == 0
puts "FizzBuzz"
Line 4,136 ⟶ 7,028:
puts n
end
end</langsyntaxhighlight>
 
=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [Stdout (lay (map fizzbuzz [1..100]))]
 
fizzbuzz :: num->[char]
fizzbuzz n = "FizzBuzz", if n mod 15 = 0
= "Fizz", if n mod 3 = 0
= "Buzz", if n mod 5 = 0
= show n, otherwise</syntaxhighlight>
 
=={{header|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.
<langsyntaxhighlight lang="sml">local
fun fbstr i =
case (i mod 3 = 0, i mod 5 = 0) of
Line 4,154 ⟶ 7,056:
fun fizzbuzz n = fizzbuzz' (n, 1)
val _ = fizzbuzz 100
end</langsyntaxhighlight>
 
Second using the standard-library combinator List.tabulate and a helper function, fb, that calculates and prints the output.
<langsyntaxhighlight lang="sml">local
fun fb i = let val fizz = i mod 3 = 0 andalso (print "Fizz"; true)
val buzz = i mod 5 = 0 andalso (print "Buzz"; true)
Line 4,164 ⟶ 7,066:
fun fizzbuzz n = (List.tabulate (n, fn i => (fb (i+1); print "\n")); ())
val _ = fizzbuzz 100
end</langsyntaxhighlight>
 
==={{header|mLite}}===
<langsyntaxhighlight lang="ocaml">local
fun fizzbuzz'
(x mod 15 = 0) = "FizzBuzz"
Line 4,182 ⟶ 7,084:
 
println ` fizzbuzz ` iota 100;
</syntaxhighlight>
</lang>
 
=={{header|MMIX}}==
<langsyntaxhighlight lang="mmix">t IS $255
Ja IS $127
 
Line 4,247 ⟶ 7,149:
JMP 1B % repeat for next i
4H XOR t,t,t
TRAP 0,Halt,0 % exit(0)</langsyntaxhighlight>
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE Fizzbuzz;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
 
TYPE CB = PROCEDURE(INTEGER);
 
PROCEDURE Fizz(n : INTEGER);
BEGIN
IF n MOD 3 = 0 THEN
WriteString("Fizz");
Buzz(n,Newline)
ELSE
Buzz(n,WriteInt)
END
END Fizz;
 
PROCEDURE Buzz(n : INTEGER; f : CB);
BEGIN
IF n MOD 5 = 0 THEN
WriteString("Buzz");
WriteLn
ELSE
f(n)
END
END Buzz;
 
PROCEDURE WriteInt(n : INTEGER);
VAR buf : ARRAY[0..9] OF CHAR;
BEGIN
FormatString("%i\n", buf, n);
WriteString(buf)
END WriteInt;
 
PROCEDURE Newline(n : INTEGER);
BEGIN
WriteLn
END Newline;
 
VAR i : INTEGER;
BEGIN
FOR i:=1 TO 30 DO
Fizz(i)
END;
 
ReadChar
END Fizzbuzz.</syntaxhighlight>
 
=={{header|Modula-3}}==
<langsyntaxhighlight lang="modula3">MODULE Fizzbuzz EXPORTS Main;
 
IMPORT IO;
Line 4,267 ⟶ 7,217:
END;
END;
END Fizzbuzz.</langsyntaxhighlight>
 
=={{header|Monte}}==
 
<langsyntaxhighlight Montelang="monte">def fizzBuzz(top):
var t := 1
while (t < top):
Line 4,284 ⟶ 7,234:
 
fizzBuzz(100)
</syntaxhighlight>
</lang>
 
=={{header|MontiLang}}==
 
<syntaxhighlight lang="montilang">&DEFINE LOOP 100&
1 VAR i .
 
FOR LOOP
|| VAR ln .
i 5 % 0 ==
IF : .
ln |Buzz| + VAR ln .
ENDIF
i 3 % 0 ==
IF : .
ln |Fizz| + VAR ln .
ENDIF
ln || ==
IF : .
i PRINT .
ENDIF
ln || !=
IF : .
ln PRINT .
ENDIF
i 1 + VAR i .
ENDFOR</syntaxhighlight>
 
=={{header|MoonScript}}==
 
<langsyntaxhighlight lang="moonscript">for i = 1,100
print ((a) -> a == "" and i or a) table.concat {
i % 3 == 0 and "Fizz" or ""
i % 5 == 0 and "Buzz" or ""}</langsyntaxhighlight>
 
=={{header|MUMPS}}==
<langsyntaxhighlight MUMPSlang="mumps">FIZZBUZZ
NEW I
FOR I=1:1:100 WRITE !,$SELECT(('(I#3)&'(I#5)):"FizzBuzz",'(I#5):"Buzz",'(I#3):"Fizz",1:I)
KILL I
QUIT</langsyntaxhighlight>
 
<langsyntaxhighlight MUMPSlang="mumps">fizzbuzz
for i=1:1:100 do write !
. write:(i#3)&(i#5) i write:'(i#3) "Fizz" write:'(i#5) "Buzz"</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
<syntaxhighlight lang="nanoquery">for i in range(1, 100)
if ((i % 3) = 0) and ((i % 5) = 0)
println "FizzBuzz"
else if i % 3 = 0
println "Fizz"
else if i % 5 = 0
println "Buzz"
else
println i
end
end</syntaxhighlight>
 
=={{header|NATURAL}}==
<syntaxhighlight lang="natural">
DEFINE DATA
LOCAL
1 #I (I4)
1 #MODULO (I4)
1 #DIVISOR (I4)
1 #OUT (A10)
END-DEFINE
*
FOR #I := 1 TO 100
#DIVISOR := 15
#OUT := 'FizzBuzz'
PERFORM MODULO
*
#DIVISOR := 5
#OUT := 'Buzz'
PERFORM MODULO
*
#DIVISOR := 3
#OUT := 'Fizz'
PERFORM MODULO
*
WRITE #I
END-FOR
*
DEFINE SUBROUTINE MODULO
#MODULO := #I - (#I / #DIVISOR) * #DIVISOR
IF #MODULO = 0
WRITE NOTITLE #OUT
ESCAPE TOP
END-IF
END-SUBROUTINE
*
END
</syntaxhighlight>
 
=={{header|Neko}}==
<langsyntaxhighlight Nekolang="neko">var i = 1
 
while(i < 100) {
Line 4,319 ⟶ 7,345:
 
i ++= 1
}</langsyntaxhighlight>
 
=={{header|Nemerle}}==
The naive approach:
<langsyntaxhighlight Nemerlelang="nemerle">using System;
using System.Console;
 
Line 4,341 ⟶ 7,367:
WriteLine($"$(FizzBuzz(i))")
}
}</langsyntaxhighlight>
A much slicker approach is [http://www.dreamincode.net/forums/blog/217/entry-3539-fizzbuzz-in-nemerle/ posted here]
 
=={{header|NetRexx}}==
<langsyntaxhighlight lang="netrexx">loop j=1 for 100
select
when j//15==0 then say 'FizzBuzz'
Line 4,352 ⟶ 7,378:
otherwise say j.right(4)
end
end</langsyntaxhighlight>
 
=={{header|Never}}==
<syntaxhighlight lang="fsharp">func fizz_buzz() -> int
{
var i = 1;
 
for (i = 1; i <= 100; i = i + 1)
{
/* if (i % 15 == 0) */
if (i % 3 == 0 && i % 5 == 0)
{
prints("Fizz Buzz\n")
}
else if (i % 3 == 0)
{
prints("Fizz\n")
}
else if (i % 5 == 0)
{
prints("Buzz\n")
}
else
{
prints(i + "\n")
}
};
 
0
}
 
func main() -> int {
fizz_buzz();
 
0
}</syntaxhighlight>
 
{{out}}
<pre>prompt$ never -f fizzbuzz.nev 2>/dev/null
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
Fizz Buzz
16
...
89
Fizz Buzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz</pre>
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">(dotimes (i 100)
(println
(cond
Line 4,361 ⟶ 7,454:
((= 0 (% i 3)) "Fizz")
((= 0 (% i 5)) "Buzz")
('t i))))</langsyntaxhighlight>
 
=={{header|NewtonScript}}==
<langsyntaxhighlight lang="newton">for i := 1 to 100 do
begin
if i mod 15 = 0 then
Line 4,375 ⟶ 7,468:
print(i);
print("\n")
end</langsyntaxhighlight>
 
=={{header|Nickle}}==
<langsyntaxhighlight lang="nickle">/* Fizzbuzz in nickle */
 
void function fizzbuzz(size) {
Line 4,389 ⟶ 7,482:
}
 
fizzbuzz(1000);</langsyntaxhighlight>
 
=={{header|Nim}}==
{{trans|Python}}
<langsyntaxhighlight lang="nim">for i in 1..100:
if i mod 15 == 0:
echo("FizzBuzz")
Line 4,401 ⟶ 7,494:
echo("Buzz")
else:
echo(i)</langsyntaxhighlight>
 
===Without Modulus===
<langsyntaxhighlight lang="nim">var messages = @["", "Fizz", "Buzz", "FizzBuzz"]
var acc = 810092048
for i in 1..100:
var c = acc and 3
echo(if c == 0: $i else: messages[c])
acc = acc shr 2 or c shl 28</langsyntaxhighlight>
 
===Using macro===
Computes everything at compile time.
<langsyntaxhighlight lang="nim">import macros
macro FizzBuzz(N): stmtuntyped =
var source = ""
for i in 1..N.intVal:
Line 4,429 ⟶ 7,522:
result = parseStmt(source)
 
FizzBuzz(100)</langsyntaxhighlight>
 
=={{header|Nix}}==
<syntaxhighlight lang="nix">with (import <nixpkgs> { }).lib;
with builtins;
let
fizzbuzz = { x ? 1 }:
''
${if (mod x 15 == 0) then
"FizzBuzz"
else if (mod x 3 == 0) then
"Fizz"
else if (mod x 5 == 0) then
"Buzz"
else
(toString x)}
'' + (if (x < 100) then
fizzbuzz { x = x + 1; } else "");
in
fizzbuzz { }</syntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
(1..100
| each {|i| $"(if $i mod 3 == 0 {"Fizz"})(if $i mod 5 == 0 {"Buzz"})"
| if ($in == "") {$i} else {$in}}
| str join "\n")
</syntaxhighlight>
 
=={{header|Oberon-2}}==
<langsyntaxhighlight lang="oberon2">MODULE FizzBuzz;
 
IMPORT Out;
Line 4,441 ⟶ 7,561:
FOR i := 1 TO 100 DO
IF i MOD 15 = 0 THEN
Out.String("FizzBuzz");
Out.Ln;
ELSIF i MOD 5 = 0 THEN
Out.String("Buzz");
Out.Ln;
ELSIF i MOD 3 = 0 THEN
Out.String("Fizz");
Out.Ln;
ELSE
Out.Int(i,0);
Out.Ln;
END;
END; Out.Ln
END
END FizzBuzz.</lang>
END FizzBuzz.</syntaxhighlight>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">bundle Default {
class Fizz {
function : Main(args : String[]) ~ Nil {
Line 4,476 ⟶ 7,593:
}
}
}</langsyntaxhighlight>
 
=={{header|Objective-C}}==
<langsyntaxhighlight lang="c">// FizzBuzz in Objective-C
#import <stdioFoundation/Foundation.h>
 
int main(int argc, char* argv[]) {
for (intNSInteger i=1; iI <=100 101; i++) {
if (i % 15 == 0) {
printfNSLog(@"FizzBuzz\n");
} else if (i % 3 == 0) {
printfNSLog(@"Fizz\n");
} else if (i % 5 == 0) {
printfNSLog(@"Buzz\n");
} else {
printfNSLog(@"%ili\n", i);
}
}
}</langsyntaxhighlight>
 
=={{header|OCaml}}==
Line 4,500 ⟶ 7,617:
Idiomatic OCaml to solve the stated problem:
 
<langsyntaxhighlight lang="ocaml">let fizzbuzz i =
match i mod 3, i mod 5 with
0, 0 -> "FizzBuzz"
Line 4,508 ⟶ 7,625:
let _ =
for i = 1 to 100 do print_endline (fizzbuzz i) done</langsyntaxhighlight>
 
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:
 
<langsyntaxhighlight 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 append s a = a^s
Line 4,520 ⟶ 7,637:
|> (i mod 5 = 0 => append "Buzz")
|> (function "" -> string_of_int i
| s -> s)</langsyntaxhighlight>
 
=={{header|Octave}}==
<langsyntaxhighlight lang="octave">for i = 1:100
if ( mod(i,15) == 0 )
disp("FizzBuzz");
Line 4,533 ⟶ 7,650:
disp(i)
endif
endfor</langsyntaxhighlight>
 
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">: fizzbuzz
| i |
100 loop: i [
Line 4,544 ⟶ 7,661:
i 5 mod ifZero: [ "Buzz" + ]
dup ifNull: [ drop i ] .
] ; </langsyntaxhighlight>
 
=={{header|Ol}}==
<syntaxhighlight lang="scheme">
(for-each (lambda (x)
(print (cond
((and (zero? (mod x 3)) (zero? (mod x 5)))
"FizzBuzz")
((zero? (mod x 3))
"Fizz")
((zero? (mod x 5))
"Buzz")
(else
x))))
(iota 100))
</syntaxhighlight>
 
=={{header|Onyx (wasm)}}==
<syntaxhighlight lang="C">
use core { * }
 
fizzbuzz :: (len: u32) -> void {
for i in 1..len+1 {
msg : str;
if (i%3 == 0 && i%5 == 0) { msg = "FizzBuzz !!!"; }
elseif (i%3 == 0) { msg = "Fizz"; }
elseif (i%5 == 0) { msg = "Buzz"; }
else { msg = tprintf("{}", i); }
printf("{}\n", msg);
}
}
 
main :: () {
fizzbuzz(100);
}
</syntaxhighlight>
 
=={{header|OOC}}==
<langsyntaxhighlight lang="ooc">fizz: func (n: Int) -> Bool {
if(n % 3 == 0) {
printf("Fizz")
Line 4,570 ⟶ 7,722:
println()
}
}</langsyntaxhighlight>
 
=={{header|Order}}==
<langsyntaxhighlight lang="c">#include <order/interpreter.h>
 
// Get FB for one number
Line 4,591 ⟶ 7,743:
ORDER_PP( // foreach instead of map, to print but return nothing
8seq_for_each(8compose(8print_el, 8fizzbuzz), 8seq_iota(1, 100))
)</langsyntaxhighlight>
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">declare
fun {FizzBuzz X}
if X mod 15 == 0 then 'FizzBuzz'
Line 4,605 ⟶ 7,757:
for I in 1..100 do
{Show {FizzBuzz I}}
end</langsyntaxhighlight>
 
=={{header|Palo Alto Tiny BASIC}}==
See [[FizzBuzz/Basic#Palo Alto Tiny BASIC|FizzBuzz/Basic]].
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">{for(n=1,100,
print(if(n%3,
if(n%5,
Line 4,622 ⟶ 7,777:
)
))
)}</langsyntaxhighlight>
 
=={{header|Pascal}}==
<langsyntaxhighlight lang="pascal">program fizzbuzz(output);
var
i: integer;
Line 4,638 ⟶ 7,793:
else
writeln(i)
end.</langsyntaxhighlight>
 
=={{header|PDP-8 Assembly}}==
{{works with| PAL-D}}
 
Runs on SimH, or any PDP-8 with an EAE
 
<syntaxhighlight lang="assembly">
/--------------------------------------------------------
/THIS PROGRAM PRINTS THE INTEGERS FROM 1 TO 100 (INCL).
/WITH THE FOLLOWING RESTRICTIONS:
/ FOR MULTIPLES OF THREE, PRINT 'FIZZ'
/ FOR MULTIPLES OF FIVE, PRINT 'BUZZ'
/ FOR MULTIPLES OF BOTH THREE AND FIVE, PRINT 'FIZZBUZZ'
/--------------------------------------------------------
 
/--------------------------------------------------------
/DEFINES
/--------------------------------------------------------
SWBA=7447 /EAE MODE A INSTRUCTION
DVI=7407 /EAE DIVIDE INSTRUCTION
AIX0=0010 /AUTO INDEX REGISTER 0
CR=0215 /CARRIAGE RETURN
LF=0212 /LINEFEED
EOT=0000 /END OF TEXT NUL
FIZMOD=0003 /CONSTANT DECIMAL 3 (FIZZ)
BUZMOD=0005 /CONSTANT DECIMAL 5 (BUZZ)
K10=0012 /CONSTANT DECIMAL 10
 
LAST=0144 /FIZZBUZZ THE NUMBERS 1..LAST
/0144 OCTAL == 100 DECIMAL
/CAN BE ANY FROM [0001...7777]
 
/--------------------------------------------------------
/FIZZBUZZ START=0200
/--------------------------------------------------------
*200 /START IN MEMORY AT 0200 OCTAL
FZZBZZ, CLA /CLEAR AC
TAD (-LAST-1 /LOAD CONSTANT -(LAST+1)
DCA CNTR /SET UP MAIN COUNTER
TAD (-FIZMOD /SET UP FIZZ COUNTER
DCA FIZCTR /TO -3
TAD (-BUZMOD /SET UP BUZZ COUNTER
DCA BUZCTR /TO -5
LOOP, ISZ CNTR /READY?
SKP /NO: CONTINUE
JMP I [7600 /YES: RETURN TO OS/8, REPLACE BY
/'HLT' IF NOT ON OS/8
CHKFIZ, ISZ FIZCTR /MULTIPLE OF 3?
JMP CHKBUZ /NO: CONTINUE
TAD FIZSTR /YES: LOAD ADDRESS OF 'FIZZ'
JMS STROUT /PRINT IT TO TTY
TAD (-FIZMOD /RELOAD THE
DCA FIZCTR /MOD 3 COUNTER
CHKBUZ, ISZ BUZCTR /MULTIPLE OF 5?
JMP CHKNUM /NO: CONTINUE
TAD BUZSTR /YES: LOAD ADDRESS OF 'BUZZ'
JMS STROUT /PRINT IT TO TTY
TAD (-BUZMOD /RELOAD THE
DCA BUZCTR /MOD 5 COUNTER
JMP NXTLIN /PRINT NEWLINE AND CONTINUE
CHKNUM, TAD FIZCTR /CHECK WHETHER MOD 3 COUNTER
TAD (FIZMOD /IS RELOADED
SNA /DID WE JUST PRINT 'FIZZ'?
JMP NXTLIN /YES: PRINT NEWLINE AND CONTINUE
CLA /ZERO THE AC
NUM, TAD CNTR /LOAD THE MAIN NUMBER COUNTER
TAD (LAST+1 /OFFSET IT TO A POSITIVE VALUE
JMS NUMOUT /PRINT IT TO THE TTY
NXTLIN, TAD LINSTR /LOAD THE ADDRESS OF THE NEWLINE
JMS STROUT /PRINT IT TO TTY
JMP LOOP /CONTINUE WITH THE NEXT NUMBER
CNTR, 0 /MAIN COUNTER
FIZCTR, 0 /FIZZ COUNTER
BUZCTR, 0 /BUZZ COUNTER
 
/--------------------------------------------------------
/WRITE ASCII CHARACTER IN AC TO TTY
/PRE : AC=ASCII CHARACTER
/POST: AC=0
/--------------------------------------------------------
CHROUT, .-.
TLS /SEND CHARACTER TO TTY
TSF /IS TTY READY FOR NEXT CHARACTER?
JMP .-1 /NO TRY AGAIN
CLA /AC=0
JMP I CHROUT /RETURN
 
/--------------------------------------------------------
/WRITE NUL TERMINATED ASCII STRING TO TTY
/PRE : AC=ADDRESS OF STRING MINUS 1
/POST: AC=0
/--------------------------------------------------------
STROUT, .-.
DCA AIX0 /STORE POINTER IN AUTO INDEX 0
STRLOP, TAD I AIX0 /GET NEXT CHARACTER FROM STRING
SNA /SKIP IF NOT EOT
JMP I STROUT /RETURN
JMS CHROUT /PRINT CHARACTER
JMP STRLOP /GO GET NEXT CHARACTER
 
/--------------------------------------------------------
/WRITE NUMBER IN AC TO TTY AS DECIMAL
/PRE : AC=UNSIGNED NUMBER BETWEEN 0000 AND 7777
/POST: AC=0
/--------------------------------------------------------
NUMOUT, .-.
SWBA /SET EAE IN MODE A
MQL /MQ=NUM; AC=0
TAD BUFFER /LOAD END OF BUFFER
DCA BUFPTR /IN BUFPTR
SKP /NUM IS ALREADY IN MQ
NUMLOP, MQL /MQ=NUM; AC=0
DVI /MQ=NUM/10; AC=NUM-(NUM/10)*10
K10 /DECIMAL 10
TAD ("0 /ADD ASCII ZERO
DCA I BUFPTR /STORE CHAR BUFFER, BACK TO FRONT
CMA /AC=-1
TAD BUFPTR /DECREMENT
DCA BUFPTR /BUFFER POINTER
MQA /MQ -> AC
SZA /READY IF ZERO
JMP NUMLOP /GET NEXT DIGIT
TAD BUFPTR /LOAD START OF CONVERTED NUMBER
JMS STROUT /SEND IT TO TTY
JMP I NUMOUT /RETURN
BUFFER, .+4 /ADDRESS OF BUFFER
*.+4 /RESERVE 4 LOCATIONS (MAX=4095)
EOT /END OF BUFFER
BUFPTR, 0 /POINTER IN BUFFER
 
/--------------------------------------------------------
/STRINGS
/--------------------------------------------------------
FIZSTR, . /FIZZ STRING
"F; "I; "Z; "Z; EOT
BUZSTR, . /BUZZ STRING
"B; "U; "Z; "Z; EOT
LINSTR, . /NEWLINE STIRNG
CR; LF; EOT
$
</syntaxhighlight>
 
Output:
<pre>
.
.PAL FIZBUZ.PA
ERRORS DETECTED: 0
LINKS GENERATED: 0
 
.LOAD FIZBUZ.BN
 
.START
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>
 
=={{header|Peloton}}==
Variable-length padded English dialect
<langsyntaxhighlight lang="sgml"><# DEFINE USERDEFINEDROUTINE LITERAL>__FizzBuzz|<# SUPPRESSAUTOMATICWHITESPACE>
<# TEST ISITMODULUSZERO PARAMETER LITERAL>1|3</#>
<# TEST ISITMODULUSZERO PARAMETER LITERAL>1|5</#>
Line 4,650 ⟶ 8,060:
<# NEITHER><# SAY PARAMETER>1</#></#>
</#></#>
<# ITERATE FORITERATION LITERAL LITERAL>100|<# ACT USERDEFINEDROUTINE POSITION FORITERATION>__FizzBuzz|...</#> </#></langsyntaxhighlight>
Fixed-length English dialect
<langsyntaxhighlight lang="sgml"><@ DEFUDRLIT>__FizzBuzz|<@ SAW>
<@ TSTMD0PARLIT>1|3</@>
<@ TSTMD0PARLIT>1|5</@>
Line 4,660 ⟶ 8,070:
<@ NTH><@ SAYPAR>1</@></@>
</@></@>
<@ ITEFORLITLIT>100|<@ ACTUDRPOSFOR>__FizzBuzz|...</@> </@></langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">
use strict;
use warnings;
Line 4,673 ⟶ 8,083:
: $i % 5 == 0 ? "Buzz"
: $i;
}</langsyntaxhighlight>
 
More concisely:
 
<langsyntaxhighlight lang="perl">print 'Fizz'x!($_ % 3) . 'Buzz'x!($_ % 5) || $_, "\n" for 1 .. 100;</langsyntaxhighlight>
 
For code-golfing:
 
<langsyntaxhighlight lang="perl">print+(Fizz)[$_%3].(Buzz)[$_%5]||$_,$/for 1..1e2</langsyntaxhighlight>
 
For array of values:
 
<langsyntaxhighlight lang="perl">map((Fizz)[$_%3].(Buzz)[$_%5]||$_,1..100);</langsyntaxhighlight>
 
Cheating:
 
<langsyntaxhighlight lang="perl">
use feature "say";
 
@a = ("FizzBuzz", 0, 0, "Fizz", 0, "Buzz", "Fizz", 0, 0, "Fizz", "Buzz", 0, "Fizz");
 
say $a[$_ % 15] || $_ for 1..100;</langsyntaxhighlight>
 
as a subroutine:
 
<langsyntaxhighlight lang="perl">
sub fizz_buzz {
join("\n", map {
Line 4,710 ⟶ 8,120:
}
print fizz_buzz;
</syntaxhighlight>
</lang>
 
By transforming a list:
=={{header|Perl 6}}==
 
{{works with|Rakudo Star|2015-09-10}}
<syntaxhighlight lang="perl">
Most straightforwardly:
<lang@FB1 perl6>for= (1 .. 100 {);
@FB2 = when map{!($_ %% (3 &or $_%5) { say ?'FizzBuzz';: $_}@FB1;
@FB3 = map{(/\d/ and when !($_ %% 3 { say ))?'Fizz';: $_}@FB2;
@FB4 = map{(/\d/ and when !($_ %% 5 { say ))?'Buzz';: $_}@FB3;
@FB5 = map{$_."\n"}@FB4;
default { .say; }
print @FB5;
}</lang>
</syntaxhighlight>
Or abusing multi subs:
<lang perl6>multi sub fizzbuzz(Int $ where * %% 15) { 'FizzBuzz' }
multi sub fizzbuzz(Int $ where * %% 5) { 'Buzz' }
multi sub fizzbuzz(Int $ where * %% 3) { 'Fizz' }
multi sub fizzbuzz(Int $number ) { $number }
(1 .. 100)».&fizzbuzz.say;</lang>
Or abusing list metaoperators:
<lang perl6>[1..100].map({[~] ($_%%3, $_%%5) »||» "" Z&& <fizz buzz> or $_ })».say</lang>
Concisely (readable):
<lang perl6>say 'Fizz' x $_ %% 3 ~ 'Buzz' x $_ %% 5 || $_ for 1 .. 100;</lang>
Shortest FizzBuzz to date:
<lang perl6>say "Fizz"x$_%%3~"Buzz"x$_%%5||$_ for 1..100</lang>
And here's an implementation that never checks for divisibility:
<lang perl6>.say for
(
(flat ('' xx 2, 'Fizz') xx *)
Z~
(flat ('' xx 4, 'Buzz') xx *)
)
Z||
1 .. 100;</lang>
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{trans|C}}
<!--<syntaxhighlight lang="phix">-->
<lang Phix>constant x = {"%d\n","Fizz\n","Buzz\n","FizzBuzz\n"}
<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>
for i=1 to 100 do
<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>
printf(1,x[1+(remainder(i,3)=0)+2*(remainder(i,5)=0)],i)
<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>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for
</lang>
<!--</syntaxhighlight>-->
Two variants with tabulated output:
<!--<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: #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: #008080;">return</span> <span style="color: #7060A8;">sprintf<span style="color: #0000FF;">(<span style="color: #0000FF;">{<span style="color: #008000;">"%-8d"<span style="color: #0000FF;">,<span style="color: #008000;">"Fizz "<span style="color: #0000FF;">,<span style="color: #008000;">"Buzz "<span style="color: #0000FF;">,<span style="color: #008000;">"FizzBuzz"<span style="color: #0000FF;">}<span style="color: #0000FF;">[<span style="color: #000000;">idx<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;">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;">)
<!--</syntaxhighlight>-->
(output same as below)
<!--<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: #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;">5</span> <span style="color: #008080;">to</span> <span style="color: #000000;">100</span> <span style="color: #008080;">by</span> <span style="color: #000000;">5</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;">"Buzz "</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;">)
<!--</syntaxhighlight>-->
{{out}}
<pre>
1 11 Fizz 31 41 Fizz 61 71 Fizz 91
2 Fizz 22 32 Fizz 52 62 Fizz 82 92
Fizz 13 23 Fizz 43 53 Fizz 73 83 Fizz
4 14 Fizz 34 44 Fizz 64 74 Fizz 94
Buzz FizzBuzz Buzz Buzz FizzBuzz Buzz Buzz FizzBuzz Buzz Buzz
Fizz 16 26 Fizz 46 56 Fizz 76 86 Fizz
7 17 Fizz 37 47 Fizz 67 77 Fizz 97
8 Fizz 28 38 Fizz 58 68 Fizz 88 98
Fizz 19 29 Fizz 49 59 Fizz 79 89 Fizz
Buzz Buzz FizzBuzz Buzz Buzz FizzBuzz Buzz Buzz FizzBuzz Buzz
</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?
<!--<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: #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;">fifteens</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;">15<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;">if</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">threes<span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">fives<span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">fifteens<span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #008000;">"%d"<span style="color: #0000FF;">,<span style="color: #000000;">i<span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">threes<span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">fives<span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">fifteens<span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #008000;">"Fizz"<span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">threes<span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">fives<span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">fifteens<span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #008000;">"Buzz"<span style="color: #0000FF;">,<span style="color: #000000;">i<span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">threes<span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">fives<span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">find<span style="color: #0000FF;">(<span style="color: #000000;">i<span style="color: #0000FF;">,<span style="color: #000000;">fifteens<span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">printf<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #008000;">"FizzBuzz"<span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</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
<!--</syntaxhighlight>-->
 
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: http://rosettacode.org/wiki/FizzBuzz
by Galileo, 10/2022 #/
 
100 for
dup print " " print dup
3 mod not if "Fizz" print endif
5 mod not if "Buzz" print endif
nl
endfor</syntaxhighlight>
{{out}}
<pre>1
2
3 Fizz
4
5 Buzz
6 Fizz
7
8
9 Fizz
10 Buzz
11
12 Fizz
13
14
15 FizzBuzz
16
17
18 Fizz
19
20 Buzz
21 Fizz
22
23
24 Fizz
25 Buzz
26
27 Fizz
28
29
30 FizzBuzz
31
32
33 Fizz
34
35 Buzz
36 Fizz
37
38
39 Fizz
40 Buzz
41
42 Fizz
43
44
45 FizzBuzz
46
47
48 Fizz
49
50 Buzz
51 Fizz
52
53
54 Fizz
55 Buzz
56
57 Fizz
58
59
60 FizzBuzz
61
62
63 Fizz
64
65 Buzz
66 Fizz
67
68
69 Fizz
70 Buzz
71
72 Fizz
73
74
75 FizzBuzz
76
77
78 Fizz
79
80 Buzz
81 Fizz
82
83
84 Fizz
85 Buzz
86
87 Fizz
88
89
90 FizzBuzz
91
92
93 Fizz
94
95 Buzz
96 Fizz
97
98
99 Fizz
100 Buzz
 
=== Press any key to exit ===</pre>
 
=={{header|PHL}}==
{{trans|C}}
<langsyntaxhighlight lang="phl">module fizzbuzz;
 
extern printf;
Line 4,774 ⟶ 8,331:
return 0;
]</langsyntaxhighlight>
 
=={{header|PHP}}==
===if/else ladder approach===
<langsyntaxhighlight lang="php"><?php
for ($i = 1; $i <= 100; $i++)
{
Line 4,790 ⟶ 8,347:
echo "$i\n";
}
?></langsyntaxhighlight>
===concatenationConcatenation 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.
 
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.
<langsyntaxhighlight lang="php"><?php
for ( $i = 1; $i <= 100; ++$i )
{
Line 4,811 ⟶ 8,368:
echo $str . "\n";
}
?></langsyntaxhighlight>
===Concatenation approach without if-s===
<syntaxhighlight lang="php"><?php
for (
$i = 0;
$i++ < 100;
$o = ($i % 3 ? '' : 'Fizz') . ($i % 5 ? '' : 'Buzz')
)
echo $o ? : $i, PHP_EOL;
?></syntaxhighlight>
 
===One Liner Approach===
<langsyntaxhighlight lang="php"><?php
for($i = 1; $i <= 100 and print(($i % 15 ? $i % 5 ? $i % 3 ? $i : 'Fizz' : 'Buzz' : 'FizzBuzz') . "\n"); ++$i);
?></langsyntaxhighlight>
 
===Compact One Liner Approach===
<syntaxhighlight lang="php">for($i=0;$i++<100;)echo($i%3?'':'Fizz').($i%5?'':'Buzz')?:$i,"\n";</syntaxhighlight>
===Array One Liner Approach===
<syntaxhighlight lang="php">for($i = 0; $i++ < 100;) echo [$i, 'Fizz', 'Buzz', 'FizzBuzz'][!($i % 3) + 2 * !($i % 5)], "\n";</syntaxhighlight>
 
=={{header|Picat}}==
Picat supports different programming styles/paradigms.
 
First some "standalone" predicates.
 
===Using a map===
<syntaxhighlight lang="picat">fizzbuzz_map =>
println(fizzbuzz_map),
FB = [I : I in 1..100],
Map = [(3="Fizz"),(5="Buzz"),(15="FizzBuzz")],
foreach(I in FB, K=V in Map)
if I mod K == 0 then
FB[I] := V
end
end,
println(FB).</syntaxhighlight>
 
===Using a template for the pattern===
<syntaxhighlight lang="picat">fizzbuzz_template1 =>
println(fizzbuzz_template1),
N = 100,
F = [_,_,fizz,_,buzz,fizz,_,_,fizz,buzz,_,fizz,_,_,fizzbuzz],
FF = [F : _I in 1..1+N div F.length].flatten(),
foreach(I in 1..N)
(var(FF[I]) -> print(I) ; print(FF[I])),
print(" ")
end,
nl.</syntaxhighlight>
 
===Another version with templates===
<syntaxhighlight lang="picat">fizzbuzz_template2 =>
println(fizzbuzz_template2),
N = 100,
F = new_list(N),
FV = [3,5,15],
FN = ["Fizz","Buzz","FizzBuzz"],
foreach(I in 1..N, {Val,Name} in zip(FV,FN))
if I mod Val == 0 then F[I] := Name end
end,
foreach(I in 1..N)
printf("%w ", cond(var(F[I]),I, F[I]))
end,
nl.</syntaxhighlight>
 
 
Below are some versions for identifying the FizzBuzziness of a number.
To be used with the following general wrapper:
<syntaxhighlight lang="picat">fizzbuzz(Goal) =>
println(Goal),
foreach(I in 1..100)
printf("%w ", apply(Goal,I))
end,
nl.</syntaxhighlight>
 
===Plain imperative approach: if/else===
<syntaxhighlight lang="picat">fb1(I) = V =>
V = I.to_string(),
if I mod 15 == 0 then V := "FizzBuzz"
elseif I mod 3 == 0 then V := "Fizz"
elseif I mod 5 == 0 then V := "Buzz"
end.</syntaxhighlight>
 
===Pattern matching + conditions in head===
<syntaxhighlight lang="picat">fb2(I) = "FizzBuzz", I mod 15 == 0 => true.
fb2(I) = "Fizz", I mod 3 == 0 => true.
fb2(I) = "Buzz", I mod 5 == 0 => true.
fb2(I) = I.to_string() => true.</syntaxhighlight>
 
===Another pattern matching approach===
<syntaxhighlight lang="picat">fb3(I) = fb3b(I, I mod 3, I mod 5).
fb3b(_I,0,0) = "FizzBuzz".
fb3b(_I,_,0) = "Buzz".
fb3b(_I,0,_) = "Fizz".
fb3b(I,_,_) = I.</syntaxhighlight>
 
===Using cond/3 and string concatenation===
<syntaxhighlight lang="picat">fb4(I) = cond(I mod 3 == 0, "Fizz", "") ++
cond(I mod 5 == 0, "Buzz", "") ++
cond(not ((I mod 3 == 0; I mod 5==0)), I.to_string(), "").</syntaxhighlight>
 
===Recursive function (conditions in head)===
<syntaxhighlight lang="picat">fizzbuzz_rec =>
print(fizzbuzz_rec),
fb5(100,[],L),
println(L).
fb5(N,L1,L), N = 0 ?=>
L = L1.reverse().
fb5(N,L1,L),N mod 15 == 0 ?=>
fb5(N-1,L1 ++ ["FizzBuzz"], L).
fb5(N,L1,L), N mod 5 == 0 ?=>
fb5(N-1,L1 ++ ["Buzz"], L).
fb5(N,L1,L), N mod 3 == 0 ?=>
fb5(N-1,L1 ++ ["Fizz"], L).
fb5(N,L1,L), N mod 3 > 0, N mod 5 > 0 =>
fb5(N-1,L1 ++ [N.to_string()], L).</syntaxhighlight>
 
===Golfing style===
<syntaxhighlight lang="picat">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().
</syntaxhighlight>
 
===Planner version===
Picat has support for "classic" planning problems. The <code>planner</code> module must be imported.
<syntaxhighlight lang="picat">import planner.
fizzbuzz_planner =>
println(fizzbuzz_planner),
plan(100,Plan),
println(Plan.reverse()),
nl.
 
final(Goal) => Goal == 0.
 
action(H,To,Move,Cost) ?=>
H mod 15 == 0,
Move = "FizzBuzz",
To = H-1,
Cost = 1.
 
action(H,To,Move,Cost) ?=>
H mod 5 == 0,
Move = "Buzz",
To = H-1,
Cost = 1.
 
action(H,To,Move,Cost) ?=>
H mod 3 == 0,
Move = "Fizz",
To = H-1,
Cost = 1.
 
action(H,To,Move,Cost) =>
H mod 3 > 0,
H mod 5 > 0,
Move = H.to_string(),
To = H-1,
Cost = 1.</syntaxhighlight>
 
 
Here we test everything.
<syntaxhighlight lang="picat">go =>
fizzbuzz_map,
fizzbuzz_template1,
fizzbuzz_template2,
fizzbuzz_planner,
fizzbuzz_rec,
fizzbuzz_golf,
 
FBs = [fb1,fb2,fb3,fb4],
foreach(FB in FBs)
call(fizzbuzz,FB)
end,
nl.</syntaxhighlight>
 
=={{header|PicoLisp}}==
We could simply use '[http://software-lab.de/doc/refA.html#at at]' here:
<langsyntaxhighlight PicoLisplang="picolisp">(for N 100
(prinl
(or (pack (at (0 . 3) "Fizz") (at (0 . 5) "Buzz")) N) ) )</lang>
 
# Above, we simply count till 100 'prin'-ting number 'at' 3rd ('Fizz'), 5th ('Buzz') and 'pack'-ing 15th number ('FizzBuzz').
# Rest of the times 'N' is printed as it loops in 'for'.
 
</syntaxhighlight>
Or do it the standard way:
<langsyntaxhighlight PicoLisplang="picolisp">(for N 100
(prinl
(cond
Line 4,829 ⟶ 8,561:
((=0 (% N 3)) "Fizz")
((=0 (% N 5)) "Buzz")
(T N) ) ) )</langsyntaxhighlight>
 
=={{header|Piet}}==
See [[FizzBuzz/EsoLang#Piet]]
 
=={{header|Pike}}==
<langsyntaxhighlight lang="pike">int main(){
for(int i = 1; i <= 100; i++) {
if(i % 15 == 0) {
Line 4,844 ⟶ 8,579:
}
}
}</langsyntaxhighlight>
 
=={{header|PILOT}}==
<langsyntaxhighlight lang="pilot">C :i = 0
*loop
C :i = i + 1
Line 4,869 ⟶ 8,604:
J : *loop
*finished
END:</langsyntaxhighlight>
 
=={{header|PIR}}==
{{works with|Parrot|tested with 2.4.0}}
<langsyntaxhighlight lang="pir">.sub main :main
.local int f
.local int mf
Line 4,906 ⟶ 8,641:
DONE:
end
.end</langsyntaxhighlight>
 
=={{header|PL/I}}==
<langsyntaxhighlight PLlang="pl/Ii">do i = 1 to 100;
select;
when (mod(i,15) = 0) put skip list ('FizzBuzz');
Line 4,916 ⟶ 8,651:
otherwise put skip list (i);
end;
end;</langsyntaxhighlight>
 
=={{header|PL/M}}==
<syntaxhighlight lang="plm">100H:
 
/* DECLARE OUTPUT IN TERMS OF CP/M -
PL/M DOES NOT COME WITH ANY STANDARD LIBRARY */
BDOS: PROCEDURE(FUNC, ARG);
DECLARE FUNC BYTE, ARG ADDRESS;
GO TO 5;
END BDOS;
 
PUT$STRING: PROCEDURE(STR);
DECLARE STR ADDRESS;
CALL BDOS(9, STR);
CALL BDOS(9, .(13,10,'$'));
END PUT$STRING;
 
/* PRINT A NUMBER */
PUT$NUMBER: PROCEDURE(N);
DECLARE S (5) BYTE INITIAL ('...$');
DECLARE P ADDRESS;
DECLARE (N, D, C BASED P) BYTE;
P = .S(3);
DIGIT:
P = P-1;
C = (N MOD 10) + '0';
N = N/10;
IF N > 0 THEN GO TO DIGIT;
CALL PUT$STRING(P);
END PUT$NUMBER;
 
/* FIZZBUZZ */
DECLARE N BYTE;
DO N = 1 TO 100;
IF N MOD 15 = 0 THEN
CALL PUT$STRING(.'FIZZBUZZ$');
ELSE IF N MOD 5 = 0 THEN
CALL PUT$STRING(.'BUZZ$');
ELSE IF N MOD 3 = 0 THEN
CALL PUT$STRING(.'FIZZ$');
ELSE
CALL PUT$NUMBER(N);
END;
 
/* EXIT TO CP/M */
CALL BDOS(0,0);
EOF</syntaxhighlight>
 
=={{header|PL/SQL}}==
<langsyntaxhighlight lang="plsql">begin
for i in 1 .. 100
loop
Line 4,933 ⟶ 8,715:
end case;
end loop;
end;</langsyntaxhighlight>
 
=={{header|Plain English}}==
<syntaxhighlight lang="text">
To play FizzBuzz up to a number:
Put "" into a string.
Loop.
If a counter is past the number, exit.
If the counter is evenly divisible by 3, append "Fizz" to the string.
If the counter is evenly divisible by 5, append "Buzz" to the string.
If the string is blank, append the counter then "" to the string.
Write the string to the console.
Clear the string.
Repeat.
 
To run:
Start up.
Play FizzBuzz up to 100.
Wait for the escape key.
Shut down.
</syntaxhighlight>
 
=={{header|Pointless}}==
<syntaxhighlight lang="pointless">
output =
range(1, 100)
|> map(fizzBuzz)
|> printLines
 
fizzBuzz(n) =
if result == "" then n else result
where result = fizzBuzzString(n)
 
fizzBuzzString(n) =
(if n % 3 == 0 then "Fizz" else "")
+ (if n % 5 == 0 then "Buzz" else "")
</syntaxhighlight>
 
=={{header|Pony}}==
<langsyntaxhighlight lang="pony">use "collections"
actor Main
Line 4,953 ⟶ 8,771:
else
n.string()
end</langsyntaxhighlight>
 
=={{header|Pop11}}==
<langsyntaxhighlight lang="pop11">lvars str;
for i from 1 to 100 do
if i rem 15 = 0 then
Line 4,968 ⟶ 8,786:
endif;
printf(str, '%s\n');
endfor;</langsyntaxhighlight>
 
=={{header|PostScript}}==
<langsyntaxhighlight lang="postscript">1 1 100 {
/c false def
dup 3 mod 0 eq { (Fizz) print /c true def } if
Line 4,977 ⟶ 8,795:
c {pop}{( ) cvs print} ifelse
(\n) print
} for</langsyntaxhighlight>
or...
<langsyntaxhighlight lang="postscript">/fizzdict 100 dict def
fizzdict begin
/notmod{ ( ) cvs } def
Line 4,989 ⟶ 8,807:
1 1 100 { mod15} for
1 1 100 { dup currentdict exch known { currentdict exch get}{notmod} ifelse print (\n) print} for
end</langsyntaxhighlight>
 
=={{header|Potion}}==
<langsyntaxhighlight lang="lua">
1 to 100 (a):
if (a % 15 == 0):
Line 5,001 ⟶ 8,819:
'Buzz'.
else: a. string print
"\n" print.</langsyntaxhighlight>
 
=={{header|PowerShell}}==
===Straightforward, looping===
<langsyntaxhighlight lang="powershell">for ($i = 1; $i -le 100; $i++) {
if ($i % 15 -eq 0) {
"FizzBuzz"
Line 5,015 ⟶ 8,833:
$i
}
}</langsyntaxhighlight>
===Pipeline, Switch===
<langsyntaxhighlight lang="powershell">$txt=$null
1..100 | ForEach-Object {
switch ($_) {
Line 5,024 ⟶ 8,842:
$_ { if($txt) { $txt } else { $_ }; $txt=$null }
}
}</langsyntaxhighlight>
 
===Concatenation===
{{trans|C#}}
<langsyntaxhighlight lang="powershell">1..100 | ForEach-Object {
$s = ''
if ($_ % 3 -eq 0) { $s += "Fizz" }
Line 5,034 ⟶ 8,852:
if (-not $s) { $s = $_ }
$s
}</langsyntaxhighlight>
 
===Piping, Evaluation, Concatenation===
<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"})")}
</syntaxhighlight>
 
===Filter, Piping, Regex Matching, Array Auto-Selection===
<langsyntaxhighlight lang="powershell">
filter fizz-buzz{
@(
Line 5,052 ⟶ 8,875:
 
1..100 | fizz-buzz
</syntaxhighlight>
</lang>
 
===String Manipulation with Regex===
<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'
</syntaxhighlight>
 
=={{header|Processing}}==
===Console & Visualization===
===Visualization & Console, Straightforward===
Reserved variable "width" in Processing is 100 pixels by default, suitable for this FizzBuzz exercise.
Accordingly, range is pixel index from 0 to 99.
<langsyntaxhighlight Processinglang="processing">for (int i = 0; i < width; i++) {
if (i % 3 == 0 && i % 5 == 0) {
stroke(255, 255, 0);
Line 5,076 ⟶ 8,904:
}
line(i, 0, i, height);
}</langsyntaxhighlight>
===VisualizationConsole & ConsoleVisualization, Ternary===
<langsyntaxhighlight Processinglang="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);
line(i, 0, i, height);
println((i % 5 == 0 && i % 3 == 0) ? "FizzBuzz!" : (i % 5 == 0) ? "Buzz" : (i % 3 == 0) ? "Fizz" : i);
}</langsyntaxhighlight>
===Console Only, Straightforward===
<langsyntaxhighlight Processinglang="processing">for (int i = 1; i <= 100; i++) {
if (i % 3 == 0) {
print("Fizz");
Line 5,095 ⟶ 8,923:
}
print("\n");
}</langsyntaxhighlight>
===Console, "Futureproof"===
<syntaxhighlight lang="processing">for(int i = 1; i <= 100; i++){
String output = "";
if(i % 3 == 0) output += "Fizz";
if(i % 5 == 0) output += "Buzz";
// copy & paste above line to add more tests
if(output == "") output = str(i);
println(output);
}</syntaxhighlight>
 
All examples produce the same console output:
 
{{out}}
Line 5,203 ⟶ 9,044:
=={{header|Prolog}}==
{{works with|SWI Prolog|4.8.0}}
{{works with|Ciao Prolog|1.21.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.
<langsyntaxhighlight lang="prolog">fizzbuzz :-
foreachforall(between(1, 100, X), print_item(X)).
 
print_item(X) :-
( 0 is X mod 15 =:= 0
-> printwrite('FizzBuzz')
; 0 is X mod 3 =:= 0
-> printwrite('Fizz')
; 0 is X mod 5 =:= 0
-> printwrite('Buzz')
; printwrite(X)
),
nl.</langsyntaxhighlight>
More conventional, doing the loop this time failure driven:
<langsyntaxhighlight lang="prolog">fizzbuzz(X) :- 0 is X mod 15 =:= 0, !, write('FizzBuzz').
fizzbuzz(X) :- 0 is X mod 3 =:= 0, !, write('Fizz').
fizzbuzz(X) :- 0 is X mod 5 =:= 0, !, write('Buzz').
fizzbuzz(X) :- write(X).
 
dofizzbuzz :- foreach(between(1, 100, X), (fizzbuzz(X), nl)), fail.</lang>
dofizzbuzz.</syntaxhighlight>
Clearer:
Clearer, doing the loop this time tail recursive, quite declarative:
<lang prolog>% N /3? /5? V
<syntaxhighlight lang="prolog">% N /3? /5? V
fizzbuzz(_, yes, yes, 'FizzBuzz').
fizzbuzz(_, yes, no, 'Fizz').
Line 5,232 ⟶ 9,075:
 
% Unifies V with 'yes' if D divides evenly into N, 'no' otherwise.
divisible_by(N, D, Vyes) :- N mod D =:= 0.
divisible_by(N, 0D, isno) :- N mod D -> V =\= yes0.
; V = no).
 
% Print 'Fizz', 'Buzz', 'FizzBuzz' or N as appropriate.
fizz_buzz_or_n(N) :- N > 100.
fizz_buzz_or_n(N) :- N =< 100,
divisible_by(N, 3, Fizz),
divisible_by(N, 53, BuzzFizz),
fizzbuzz divisible_by(N, Fizz5, Buzz, FB),
format fizzbuzz("~pN, -> ~p~n"Fizz, [NBuzz, FB]).,
write(FB), nl,
M is N+1, fizz_buzz_or_n(M).
 
main :-
foreach(between(1,100, N), fizz_buzz_or_n(N)1).</langsyntaxhighlight>
 
Using modern Prolog techniques, resulting in idiomatic, highly declarative code:
 
{{works with|SWI Prolog|8.2.1}} {{works with|Scryer Prolog|0.7.8}}
<syntaxhighlight lang="prolog">
% This implementation uses modern Prolog techniques
% in order to be an idiomatic solution that uses logical purity, generality and determinism wherever possible:
% - CLP(Z): constraint logic programming on integers.
% - library(reif): efficient logical predicates based on 'Indexing dif/2'.
:- module(fizz_buzz, [main/0, integer_fizzbuzz_below_100/2, integer_fizzbuzz/2]).
 
:- use_module(library(reif)).
 
% for Scryer-Prolog:
:- use_module(library(clpz)).
:- use_module(library(between)).
:- use_module(library(iso_ext)).
:- use_module(library(si)).
 
% for SWI-Prolog:
% :- use_module(library(clpfd)).
 
% Prints all solutions to `integer_fizzbuzz_below_100` each on a separate line, in order.
% Logically-impure shell, as currently there is no logically-pure way to write to a filestream.
main :-
forall(integer_fizzbuzz_below_100(_, FizzBuzz), write_line(FizzBuzz)).
 
write_line(Value) :-
write(Value),
nl.
 
% Constrains FizzBuzz results to the range 1 <= X <= 100,
% and (for the 'most general query' where neither X or FizzBuzz is concrete)
% ensures results are traversed in order low -> high X.
%
% ?- integer_fizzbuzz_below_100(X, FizzBuzz) % generate all the results in order
% ?- integer_fizzbuzz_below_100(27, Result) % Find out what output `27` will produce (it's 'Fizz'.)
% ?- integer_fizzbuzz_below_100(X, 'Fizz') % generate all the numbers which would print 'Fizz' in order (3, 6, 9, etc).
% ?- integer_fizzbuzz_below_100(X, Res), integer_si(Res) % generate all the numbers which would print themselves in order (1, 2, 4, 6, 7, 8, 11, etc).
% ?- integer_fizzbuzz_below_100(X, Res), is_of_type(integer, Res) % SWI-Prolog version doing the same.
integer_fizzbuzz_below_100(X, FizzBuzz) :-
between(1, 100, X),
integer_fizzbuzz(X, FizzBuzz).
 
% States the relationship between a number
% and its FizzBuzz representation.
%
% Because constraints are propagated lazily,
% prompting this predicate without having constrained `Num`
% to a particular integer value will give you its definition back.
% Put differently: This predicate returns the whole solution space at once,
% and external labeling techniques are required to traverse and concretize this solution space
% in an order that we like.
integer_fizzbuzz(Num, FizzBuzz) :-
if_(Num mod 15 #= 0, FizzBuzz = 'FizzBuzz',
if_(Num mod 5 #= 0, FizzBuzz = 'Buzz',
if_(Num mod 3 #= 0, FizzBuzz = 'Fizz',
Num = FizzBuzz)
)
).
 
% Reifiable `#=`.
#=(X, Y, T) :-
X #= X1,
Y #= Y1,
zcompare(C, X1, Y1),
eq_t(C, T).
 
eq_t(=, true).
eq_t(<, false).
eq_t(>, false).
 
</syntaxhighlight>
 
=={{header|PureBasic}}==
Line 5,250 ⟶ 9,167:
 
=={{header|Pyret}}==
<syntaxhighlight lang="pyret">fun fizzbuzz(n :: NumPositive) -> String:
<lang pyret>is-positive = _ > 0 # equivalent to lam(x): x > 0 end
 
fun fizzbuzz(n :: Number%(is-positive)) -> String:
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.```
Line 5,269 ⟶ 9,184:
end
 
range(1, 101).map(fizzbuzz).each(print)</syntaxhighlight>
 
</lang>
 
=={{header|Python}}==
===PythonPython2: Simple===
<langsyntaxhighlight lang="python">for i in xrangerange(1, 101):
if i % 15 == 0:
print "FizzBuzz"
Line 5,283 ⟶ 9,196:
print "Buzz"
else:
print i</langsyntaxhighlight>
 
===Python3: Simple===
<syntaxhighlight lang="python">for i in range(1, 101):
if i % 15 == 0:
print("FizzBuzz")
elif i % 3 == 0:
print("Fizz")
elif i % 5 == 0:
print("Buzz")
else:
print(i)</syntaxhighlight>
 
===Python: Simple - no duplication ===
<syntaxhighlight lang="python">for n in range(1,101):
response = ''
 
if not n%3:
response += 'Fizz'
if not n%5:
response += 'Buzz'
 
print(response or n)
</syntaxhighlight>
One liner using string concatenation:
<langsyntaxhighlight lang="python">for i in range(1,101): print("Fizz"*(i%3==0) + "Buzz"*(i%5==0) or i)</langsyntaxhighlight>
 
One liner another code:
<langsyntaxhighlight lang="python">for i in range(100):print(i%3//2*'Fizz'+i%5//4*'Buzz'or i+1)</langsyntaxhighlight>
 
List Comprehensions:
<langsyntaxhighlight lang="python">
for n in range(1, 100):
fb = ''.join([ denom[1] if n % denom[0] == 0 else '' for denom in [(3,'fizz'),(5,'buzz')] ])
print fb if fb else n
</syntaxhighlight>
</lang>
Another list comprehension:
<syntaxhighlight lang="python">
print (', '.join([(x%3<1)*'Fizz'+(x%5<1)*'Buzz' or str(x) for x in range(1,101)]))
</syntaxhighlight>
 
===Python: List Comprehension (Python 3)===
<langsyntaxhighlight 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)]</langsyntaxhighlight>
 
===Python: Lazily===
You can also create a lazy, unbounded sequence by using generator expressions:
<langsyntaxhighlight lang="python">from itertools import cycle, izip, count, islice
 
fizzes = cycle([""] * 2 + ["Fizz"])
Line 5,315 ⟶ 9,254:
# print the first 100
for i in islice(fizzbuzz, 100):
print i</langsyntaxhighlight>
 
=={{header|Q}}==
 
Or equivalently, in terms of map, and Python 3 libraries:
<lang Q>
{{Works with|Python|3.7}}
{$[0=x mod 15;"FizzBuzz";0=x mod 5;"Buzz";0=x mod 3;"Fizz";string x]} each 1+til 15</lang>
<syntaxhighlight lang="python">'''Fizz buzz'''
 
from itertools import count, cycle, islice
Or to print the result:
 
<lang Q>
 
-1 "\n" sv{$[0=x mod 15;"FizzBuzz";0=x mod 5;"Buzz";0=x mod 3;"Fizz";string x]} each 1+til 15;</lang>
# fizzBuzz :: () -> Generator [String]
def fizzBuzz():
'''A non-finite stream of fizzbuzz terms.
'''
return map(
lambda f, b, n: (f + b) or str(n),
cycle([''] * 2 + ['Fizz']),
cycle([''] * 4 + ['Buzz']),
count(1)
)
 
 
# ------------------------- TEST -------------------------
def main():
'''Display of first 100 terms of the fizzbuzz series.
'''
print(
'\n'.join(
list(islice(
fizzBuzz(),
100
))
)
)
 
 
if __name__ == '__main__':
main()</syntaxhighlight>
 
===Python3.8: With walrus operator===
 
<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===
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.
<syntaxhighlight lang="python">
def numsum(n):
''' The recursive sum of all digits in a number
unit a single character is obtained'''
res = sum([int(i) for i in str(n)])
if res < 10: return res
else : return numsum(res)
for n in range(1,101):
response = 'Fizz'*(numsum(n) in [3,6,9]) + \
'Buzz'*(str(n)[-1] in ['5','0'])\
or n
print(response)
</syntaxhighlight>
 
===Python3: Super concise: 1 line===
<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)))
</syntaxhighlight>
 
=={{header|q}}==
 
q is the query language for '''kdb+'''.
 
<syntaxhighlight lang="q">
{(2 sv not x mod/:5 3)'[;`fizz;`buzz;`fizzbuzz]`$string x}</syntaxhighlight>
 
 
Usage:
<syntaxhighlight lang="q">
q)/ Fizzbuzz
q)fb:{(2 sv not x mod/:5 3)'[;`fizz;`buzz;`fizzbuzz]`$string x}
q)fb 1+til 20
`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/<br>
https://code.kx.com/q/ref/sv/<br>
https://code.kx.com/q/ref/maps/#case
 
Explanation:
<syntaxhighlight lang="q">
q)show x:1+til 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
q)x mod/:5 3
1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0
1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2
q)not x mod/:5 3
00001000010000100001b
00100100100100100100b
q)show i:2 sv not x mod/:5 3 / binary decode
0 0 1 0 2 1 0 0 1 2 0 1 0 0 3 0 0 1 0 2
q)(`$string x;`fizz;`buzz;`fizzbuzz)
`1`2`3`4`5`6`7`8`9`10`11`12`13`14`15`16`17`18`19`20
`fizz
`buzz
`fizzbuzz
q)i'[`$string x;`fizz;`buzz;`fizzbuzz] / Case iterator
`1`2`fizz`4`buzz`fizz`7`8`fizz`buzz`11`fizz`13`14`fizzbuzz`16`17`fizz`19`buzz</syntaxhighlight>
 
=={{header|QB64}}==
<syntaxhighlight lang="qb64">For n = 1 To 100
If n Mod 15 = 0 Then
Print "FizzBuzz"
ElseIf n Mod 5 = 0 Then
Print "Buzz"
ElseIf n Mod 3 = 0 Then
Print "Fizz"
Else
Print n
End If
Next</syntaxhighlight>
 
=={{header|Quackery}}==
<syntaxhighlight lang="quackery"> 100 times
[ i^ 1+ true
over 3 mod not
if [ say "fizz" drop false ]
over 5 mod not
if [ say "buzz" drop false ]
iff echo else drop
sp ]
</syntaxhighlight>
 
=={{header|R}}==
<langsyntaxhighlight Rlang="rsplus">xx <- x <- 1:100
xx[x %% 3 == 0] <- "Fizz"
xx[x %% 5 == 0] <- "Buzz"
xx[x %% 15 == 0] <- "FizzBuzz"
xx</langsyntaxhighlight>
 
Or, without directly checking for divisibility by 15:
<langsyntaxhighlight Rlang="rsplus">xx <- rep("", 100)
x <- 1:100
xx[x %% 3 == 0] <- paste0(xx[x %% 3 == 0], "Fizz")
xx[x %% 5 == 0] <- paste0(xx[x %% 5 == 0], "Buzz")
xx[xx == ""] <- x[xx == ""]
xx</langsyntaxhighlight>
 
Or, (ab)using the vector recycling rule:
<langsyntaxhighlight Rlang="rsplus">x <- pastepaste0(rep("", 100), c("", "", "Fizz"), c("", "", "", "", "Buzz"), sep="")
cat(ifelse(x == "", 1:100, x), sep = "\n")</langsyntaxhighlight>
 
Or, for an abuse of the recycling rules that could be generalised:
<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")</syntaxhighlight>
 
Or, with a more straightforward use of ifelse:
<langsyntaxhighlight Rlang="rsplus">x <- 1:100
ifelse(x %% 15 == 0, 'FizzBuzz',
ifelse(x %% 5 == 0, 'Buzz',
ifelse(x %% 3 == 0, 'Fizz', x)))</langsyntaxhighlight>
Or, adapting from [https://rosettacode.org/wiki/General_FizzBuzz#Names_solution General FizzBuzz#Names solution]:
<syntaxhighlight lang="rsplus">namedNums <- c(Fizz = 3, Buzz = 5)
for(i in 1:100)
{
isFactor <- i %% namedNums == 0
print(if(any(isFactor)) paste0(names(namedNums)[isFactor], collapse = "") else i)
}</syntaxhighlight>
 
=={{header|Racket}}==
<syntaxhighlight lang="racket">#lang racket
<lang racket>(for ([n (in-range 1 101)])
 
(for ([n (in-range 1 101)])
(displayln
(match (gcd n 15)
Line 5,358 ⟶ 9,427:
[3 "fizz"]
[5 "buzz"]
[_ n])))</langsyntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo Star|2015-09-10}}
Most straightforwardly:
<syntaxhighlight lang="raku" line>for 1 .. 100 {
when $_ %% (3 & 5) { say 'FizzBuzz'; }
when $_ %% 3 { say 'Fizz'; }
when $_ %% 5 { say 'Buzz'; }
default { .say; }
}</syntaxhighlight>
Or abusing multi subs:
<syntaxhighlight lang="raku" line>multi sub fizzbuzz(Int $ where * %% 15) { 'FizzBuzz' }
multi sub fizzbuzz(Int $ where * %% 5) { 'Buzz' }
multi sub fizzbuzz(Int $ where * %% 3) { 'Fizz' }
multi sub fizzbuzz(Int $number ) { $number }
(1 .. 100)».&fizzbuzz.say;</syntaxhighlight>
Or abusing list metaoperators:
<syntaxhighlight lang="raku" line>[1..100].map({[~] ($_%%3, $_%%5) »||» "" Z&& <fizz buzz> or $_ })».say</syntaxhighlight>
Concisely (readable):
<syntaxhighlight lang="raku" line>say 'Fizz' x $_ %% 3 ~ 'Buzz' x $_ %% 5 || $_ for 1 .. 100;</syntaxhighlight>
Shortest FizzBuzz to date:
<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:
<syntaxhighlight lang="raku" line>.say for
(
(flat ('' xx 2, 'Fizz') xx *)
Z~
(flat ('' xx 4, 'Buzz') xx *)
)
Z||
1 .. 100;</syntaxhighlight>
 
=={{header|RapidQ}}==
The [[#BASIC|BASIC]] solutions work with RapidQ, too.
However, here is a bit more esoteric solution using the IIF() function.
<langsyntaxhighlight lang="rapidq">FOR i=1 TO 100
t$ = IIF(i MOD 3 = 0, "Fizz", "") + IIF(i MOD 5 = 0, "Buzz", "")
PRINT IIF(LEN(t$), t$, i)
NEXT i</langsyntaxhighlight>
 
=={{header|Rascal}}==
<langsyntaxhighlight lang="rascal">import IO;
 
public void fizzbuzz() {
Line 5,376 ⟶ 9,477:
println((fb == "") ?"<n>" : fb);
}
}</langsyntaxhighlight>
 
=={{header|Raven}}==
<langsyntaxhighlight lang="raven">100 each 1 + as n
''
n 3 mod 0 = if 'Fizz' cat
n 5 mod 0 = if 'Buzz' cat
dup empty if drop n
say</langsyntaxhighlight>
 
=={{header|REALbasic}}==
See [[FizzBuzz/Basic]]
 
=={{header|ReasonReasonML}}==
<syntaxhighlight lang="ocaml">
<lang Reason>
let fizzbuzz i =>
switch (i mod 3, i mod 5) {
Line 5,402 ⟶ 9,503:
print_endline (fizzbuzz i)
};
</syntaxhighlight>
</lang>
 
=={{header|REBOL}}==
An implementation that concatenates strings and includes a proper code header (title, date, etc.)
Shortest implementation:
<syntaxhighlight lang="rebol">REBOL [
<lang REBOL>repeat i 100 [case/all [i // 3 = 0 [print"fizz"] i // 5 = 0 [print "buzz"] 1 [print i]]]</lang>
A long implementation that concatenates strings and includes a proper code header (title, date, etc.)
<lang REBOL>REBOL [
Title: "FizzBuzz"
Author: oofoe
Date: 2009-12-10
URL: http://rosettacode.org/wiki/FizzBuzz
]
Line 5,427 ⟶ 9,524:
]
print x
]</langsyntaxhighlight>
Here areis twoan examplesexample by Nick Antonaccio.
<langsyntaxhighlight REBOLlang="rebol">repeat i 100 [
print switch/default 0 compose [
(mod i 15) ["fizzbuzz"]
Line 5,435 ⟶ 9,532:
(mod i 5) ["buzz"]
][i]
]</syntaxhighlight>
]
 
; And a minimized version:
<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>
 
repeat i 100[j:""if 0 = mod i 3[j:"fizz"]if 0 = mod i 5[j: join j"buzz"]if j =""[j: i]print j]</lang>
The following is presented as a curiosity only, not as an example of good coding practice:
<langsyntaxhighlight REBOLlang="rebol">m: func [i d] [0 = mod i d]
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" ""]]
repeat i 100 [print spick z: zz i z i]</langsyntaxhighlight>
 
=={{header|Red}}==
<syntaxhighlight lang="red">Red [Title: "FizzBuzz"]
 
repeat i 100 [
print case [
i % 15 = 0 ["FizzBuzz"]
i % 5 = 0 ["Buzz"]
i % 3 = 0 ["Fizz"]
true [i]
]
]</syntaxhighlight>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <FizzBuzz 1>;
};
 
FizzBuzz {
101 = ;
s.N = <Prout <Item s.N>>
<FizzBuzz <+ 1 s.N>>;
};
 
Item {
s.N, <Mod s.N 15>: 0 = FizzBuzz;
s.N, <Mod s.N 5>: 0 = Buzz;
s.N, <Mod s.N 3>: 0 = Fizz;
s.N = s.N;
};</syntaxhighlight>
 
=={{header|Retro}}==
This is a port of some [http://weblog.raganwald.com/2007/01/dont-overthink-fizzbuzz.html Forth code].
<langsyntaxhighlight Retrolang="retro">: fizz? ( s-f ) 3 mod 0 = ;
: buzz? ( s-f ) 5 mod 0 = ;
: num? ( s-f ) dup fizz? swap buzz? or 0 = ;
Line 5,455 ⟶ 9,582:
: ?num ( s- ) num? &putn &drop if ;
: fizzbuzz ( s- ) dup ?fizz dup ?buzz dup ?num space ;
: all ( - ) 100 [ 1+ fizzbuzz ] iter ;</langsyntaxhighlight>
It's cleaner to use quotes and combinators though:
<langsyntaxhighlight Retrolang="retro">needs math'
: <fizzbuzz>
[ 15 ^math'divisor? ] [ drop "FizzBuzz" puts ] when
[ 3 ^math'divisor? ] [ drop "Fizz" puts ] when
[ 5 ^math'divisor? ] [ drop "Buzz" puts ] when putn ;
: fizzbuzz cr 100 [ 1+ <fizzbuzz> space ] iter ;</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 5,468 ⟶ 9,595:
This version's program logic closely mirrors the problem statement:
===three IF-THEN===
<langsyntaxhighlight lang="rexx">/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
/*╔═══════════════════════════════════╗*/
do j=1 to 100; z= j /*║ ║*/
Line 5,475 ⟶ 9,602:
if j//(3*5)==0 then z= 'FizzBuzz' /*║ ║*/
say right(z, 8) /*╚═══════════════════════════════════╝*/
end /*j*/ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
'''output'''
<pre style="height:40ex">
Line 5,583 ⟶ 9,710:
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.
<langsyntaxhighlight lang="rexx">/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
/*╔═══════════════════════════════════╗*/
do j=1 to 100 /*║ ║*/
Line 5,592 ⟶ 9,719:
otherwise say right(j, 8) /*╚═══════════════════════════════════╝*/
end /*select*/
end /*j*/ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
'''output''' &nbsp; is identical to the 1<sup>st</sup> REXX version.
 
===two IF-THEN===
This version lends itself to expansion &nbsp; (such as using &nbsp; '''Jazz''' &nbsp; for multiples of &nbsp; '''7''').
<langsyntaxhighlight lang="rexx">/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
 
do j=1 for 100; _=
Line 5,604 ⟶ 9,731:
/* if j//7 ==0 then _=_'Jazz' */ /* ◄─── note that this is a comment. */
say right(word(_ j,1),8)
end /*j*/ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
'''output''' &nbsp; is identical to the 1<sup>st</sup> REXX version.
 
==="geek" version===
<langsyntaxhighlight lang="rexx">/*REXX program displays numbers 1 ──► 100 (some transformed) for the FizzBuzz problem.*/
/* [↓] concise, but somewhat obtuse. */
do j=1 for 100
say right(word(word('Fizz', 1+(j//3\==0))word('Buzz', 1+(j//5\==0)) j, 1), 8)
end /*j*/
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
'''output''' &nbsp; is identical to the 1<sup>st</sup> REXX version. <br><br>
 
=={{header|Rhovas}}==
Standard FizzBuzz using a pattern matching approach:
* <code>range(1, 100, :incl)</code> creates an inclusion range
* <code>.for {</code> iterates through the range, with the current element being <code>val</code>
* Pattern matching on <code>[val.mod(3), val.mod(5)]</code> is used to check divisibility conditions
** <code>[0, 0]</code>, for instance, matches when <code>val</code>is divisible by both <code>3</code> and <code>5</code>
** <code>else</code> matches all other possibilities, in this case when <code>val</code> is not divisible by <code>3</code> or <code>5</code>
 
<syntaxhighlight lang="scala">
range(1, 100, :incl).for {
match ([val.mod(3), val.mod(5)]) {
[0, 0]: print("FizzBuzz");
[0, _]: print("Fizz");
[_, 0]: print("Buzz");
else: print(val);
}
};
</syntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
for n = 1 to 100
if n % 15 = 0 see "" + n + " = " + "FizzBuzz" + nl loop
but n % 3 = 0 see "" + n + " = " + "Fizz"+ nl
but n % 5 = 0 see "" + n + " = " + "Buzz" + nl
but n % 3 = 0 see "" + n + " = " + "Fizz" + nl
else see "" + n + " = " + n + nl ok
next</syntaxhighlight>
next
 
</lang>
{{out}}
Limited to first 20.
<pre>
1 = 1
2 = 2
3 = Fizz
4 = 4
5 = Buzz
6 = Fizz
7 = 7
8 = 8
9 = Fizz
10 = Buzz
11 = 11
12 = Fizz
13 = 13
14 = 14
15 = FizzBuzz
16 = 16
17 = 17
18 = Fizz
19 = 19
20 = Buzz
</pre>
 
=={{header|Robotic}}==
<syntaxhighlight lang="robotic">
set "local1" to 1
: "loop"
wait for 10
if "('local1' % 15)" = 0 then "fizzbuzz"
if "('local1' % 3)" = 0 then "fizz"
if "('local1' % 5)" = 0 then "buzz"
* "&local1&"
: "inc"
inc "local1" by 1
if "local1" <= 100 then "loop"
goto "done"
 
: "fizzbuzz"
* "FizzBuzz"
goto "inc"
 
: "fizz"
* "Fizz"
goto "inc"
 
: "buzz"
* "Buzz"
goto "inc"
 
: "done"
end
</syntaxhighlight>
 
The '''wait for 10''' function is not really necessary, but it helps to slow down the output.
 
=={{header|Rockstar}}==
 
Midnight takes your heart and your soul
While your heart is as high as your soul
Put your heart without your soul into your heart
Give back your heart
Desire is a lovestruck ladykiller
My world is nothing
Fire is ice
Hate is water
Until my world is Desire,
Build my world up
If Midnight taking my world, Fire is nothing and Midnight taking my world, Hate is nothing
Shout "FizzBuzz!"
Take it to the top
If Midnight taking my world, Fire is nothing
Shout "Fizz!"
Take it to the top
If Midnight taking my world, Hate is nothing
Say "Buzz!"
Take it to the top
Whisper my world
 
=={{header|RPG}}==
<nowiki>**</nowiki>free
dcl-s ix Int(5);
for ix = 1 to 100;
select;
when %rem(ix:15) = 0;
dsply 'FizzBuzz';
when %rem(ix:5) = 0;
dsply 'Buzz';
when %rem(ix:3) = 0;
dsply 'Fizz';
other;
dsply (%char(ix));
endsl;
endfor;
 
=={{header|RPL}}==
Structured programming:
≪ { } 1 100 '''FOR''' j
'''IF''' j 3 MOD '''THEN''' "" '''ELSE''' "Fizz" '''END'''
'''IF''' j 5 MOD NOT '''THEN''' "Buzz" + '''END'''
'''IF''' DUP SIZE NOT '''THEN''' DROP j '''END'''
+ '''NEXT'''
≫ ''''FIZZB'''' STO
Arithmetic:
≪ { } 1 100 '''FOR''' j
j 3 MOD NOT j 5 MOD NOT → a b
≪ '''IF''' a b + '''THEN''' "FizzBuzz" 5 4 a * - a b 2 * MAX 4 * SUB '''ELSE''' j '''END'''
≫ + '''NEXT'''
≫ ''''FIZZB'''' STO
Data-centric:
≪ "FizzBuzz" { (1,4) (5,8) (1,8) } → fb idx
≪ { } 1 100 '''FOR''' j
'''IF''' j 3 MOD NOT j 5 MOD NOT 2 * + '''THEN''' fb idx LAST GET C→R SUB '''ELSE''' j '''END'''
+ '''NEXT'''
≫ ≫ ''''FIZZB'''' STO
Esoteric one-liner:
≪ ≪ j ROT MOD "" ROT IFTE ≫ → f ≪ { } 1 100 FOR j 3 "Fizz" f EVAL 5 "Buzz" f EVAL + SIZE LAST j IFTE + NEXT ≫ ≫ EVAL
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">1.upto(100) do |n|
print "Fizz" if a = (n % 3).zero?
print "Buzz" if b = (n % 5).zero?
print n unless (a || b)
puts
end</langsyntaxhighlight>
A bit more straightforward:
<langsyntaxhighlight lang="ruby">(1..100).each do |n|
puts if (n % 15).zero?
"FizzBuzz"
Line 5,644 ⟶ 9,914:
n
end
end</langsyntaxhighlight>
Enumerable#Lazy and classes:
 
Line 5,650 ⟶ 9,920:
 
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]
<langsyntaxhighlight lang="ruby">
class Enumerator::Lazy
def filter_map
Line 5,742 ⟶ 10,012:
min(2,b) if b < f and b < fb
min(0,fb) if fb < b and fb < f
end</langsyntaxhighlight>
 
An example using string interpolation:
<langsyntaxhighlight lang="ruby">(1..100).each do |n|
v = "#{"Fizz" if n % 3 == 0}#{"Buzz" if n % 5 == 0}"
puts v.empty? ? n : v
end</langsyntaxhighlight>
 
Interpolation inspired one-liner:
<langsyntaxhighlight 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}" }</langsyntaxhighlight>
 
An example using append:
<langsyntaxhighlight lang="ruby">1.upto 100 do |n|
r = ''
r << 'Fizz' if n % 3 == 0
Line 5,760 ⟶ 10,030:
r << n.to_s if r.empty?
puts r
end</langsyntaxhighlight>
 
Yet another solution:
<syntaxhighlight lang="text">1.upto(100) { |i| puts "#{[:Fizz][i%3]}#{[:Buzz][i%5]}"[/.+/] || i }</langsyntaxhighlight>
 
Yet another solution:
<langsyntaxhighlight lang="ruby">1.upto(100){|i|puts'FizzBuzz '[n=i**4%-15,n+13]||i}</langsyntaxhighlight>
 
Used Enumerable#cycle:
<langsyntaxhighlight lang="ruby">f = [nil, nil, :Fizz].cycle
b = [nil, nil, nil, nil, :Buzz].cycle
(1..100).each do |i|
puts "#{f.next}#{b.next}"[/.+/] || i
end</langsyntaxhighlight>
 
After beforehand preparing the Array which put the number from 1 to 100, it processes.
<langsyntaxhighlight lang="ruby">seq = *0..100
{Fizz:3, Buzz:5, FizzBuzz:15}.each{|k,n| n.step(100,n){|i|seq[i]=k}}
puts seq.drop(1)</langsyntaxhighlight>
 
Monkeypatch example:
<langsyntaxhighlight lang="ruby">class Integer
def fizzbuzz
v = "#{"Fizz" if self % 3 == 0}#{"Buzz" if self % 5 == 0}"
Line 5,788 ⟶ 10,058:
end
 
puts *(1..100).map(&:fizzbuzz)</langsyntaxhighlight>
 
Without mutable variables or inline printing.
<langsyntaxhighlight lang="ruby">fizzbuzz = ->(i) do
(i%15).zero? and next "FizzBuzz"
(i%3).zero? and next "Fizz"
Line 5,798 ⟶ 10,068:
end
 
puts (1..100).map(&fizzbuzz).join("\n")</langsyntaxhighlight>
[[Jump anywhere#Ruby]] has a worse example of FizzBuzz, using a continuation!
 
Using Ruby 3's Pattern Matching:
<syntaxhighlight lang="ruby">
1.upto(100) do |n|
puts case [(n % 3).zero?, (n % 5).zero?]
in true, false
"Fizz"
in false, true
"Buzz"
in true, true
"FizzBuzz"
else
n
end
end
</syntaxhighlight>
 
=={{header|Ruby with RSpec}}==
Line 5,807 ⟶ 10,093:
Your spec/fizzbuzz_spec.rb file should like this:
 
<langsyntaxhighlight lang="ruby">
require 'fizzbuzz'
 
Line 5,848 ⟶ 10,134:
end
end
</langsyntaxhighlight>
 
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:
 
<langsyntaxhighlight lang="ruby">
def fizzbuzz(number)
return 'FizzBuzz' if is_divisible_by_fifteen?(number)
Line 5,876 ⟶ 10,162:
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].
Line 5,884 ⟶ 10,170:
 
=={{header|Rust}}==
A version using an iterator and immutable data:
 
Basic example with a for loop and match:
<lang rust>use std::borrow::Cow; // Allows us to avoid unnecessary allocations
<syntaxhighlight lang="rust">fn main() {
for i in 1..=100 {
(1..101).map(|n| match (n % 3, n % 5) {
match (0i % 3, 0)i =>% "FizzBuzz".into(5), {
(0, _0) => println!("Fizzfizzbuzz".into(),
(_0, 0_) => println!("Buzzfizz".into(),
(_, 0) => Cow::fromprintln!(n.to_string()"buzz"),
}).for_each (|n|_, _) => println!("{}", ni));,
}
}
}
</lang>
}</syntaxhighlight>
 
OrUsing a version unwrapping thean iterator intoand aimmutable loopdata:
 
<syntaxhighlight lang="rust">use std::borrow::Cow;
 
<lang rust>
use std::borrow::Cow;
fn main() {
for i in (1..101 {=100)
println!.map("{}",|n| match (in % 3, in % 5) {
(0, 0) => "FizzBuzz".into(),
(0, _) => "Fizz".into(),
(_, 0) => "Buzz".into(),
_ => Cow::from(in.to_string()),
});
.for_each(|n| println!("{:?}", n));
}
}
}</lang>
</syntaxhighlight>
 
A folding iterator version, buffered with a single string allocation, by making use of expressions the <code>write!</code> macro.
 
<syntaxhighlight lang="rust">use std::fmt::Write;
 
fn fizzbuzz() -> String {
(1..=100).fold(String::new(), |mut output, x| {
let fizz = if x % 3 == 0 { "fizz" } else { "" };
let buzz = if x % 5 == 0 { "buzz" } else { "" };
if fizz.len() + buzz.len() != 0 {
output + fizz + buzz + "\n"
} else {
write!(&mut output, "{}", x).unwrap();
output + "\n"
}
})
}
 
fn main() {
println!("{}", fizzbuzz());
}</syntaxhighlight>
 
Or the ultimate optimized version with hardcoded output, no standard library or main function, and direct assembly syscalls to write to stdout.
<syntaxhighlight lang ="rust"> #![no_std]
#![feature(asm, lang_items, libc, no_std, start)]
Line 5,949 ⟶ 10,257:
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] extern fn panic_fmt() {}</langsyntaxhighlight>
 
=={{header|Salmon}}==
<langsyntaxhighlight Salmonlang="salmon">iterate (x; [1...100])
((x % 15 == 0) ? "FizzBuzz" :
((x % 3 == 0) ? "Fizz" :
((x % 5 == 0) ? "Buzz" : x)))!;</langsyntaxhighlight>
or
<langsyntaxhighlight Salmonlang="salmon">iterate (x; [1...100])
{
if (x % 15 == 0)
Line 5,967 ⟶ 10,275:
else
x!;
};</langsyntaxhighlight>
 
=={{header|SAS}}==
<langsyntaxhighlight SASlang="sas">data _null_;
do i=1 to 100;
if mod(i,15)=0 then put "FizzBuzz";
Line 5,977 ⟶ 10,285:
else put i;
end;
run;</langsyntaxhighlight>
 
=={{header|Sather}}==
<langsyntaxhighlight lang="sather">class MAIN is
main is
loop i ::= 1.upto!(100);
Line 5,993 ⟶ 10,301:
end;
end;
end;</langsyntaxhighlight>
 
=={{header|Scala}}==
Line 5,999 ⟶ 10,307:
 
===Idiomatic scala code===
<langsyntaxhighlight lang="scala">object FizzBuzz extends App {
1 to 100 foreach { n =>
println((n % 3, n % 5) match {
Line 6,008 ⟶ 10,316:
})
}
}</langsyntaxhighlight>
 
===Geeky over-generalized solution ☺===
<langsyntaxhighlight 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) =>
a fold(_ => b, s => b fold(_ => a, t => Right(s + t))))
Line 6,017 ⟶ 10,325:
def fizzbuzz = replaceMultiples(_: Int, 3 -> "Fizz", 5 -> "Buzz") fold(_.toString, identity)
 
1 to 100 map fizzbuzz foreach println</langsyntaxhighlight>
 
===By a two-liners geek===
<langsyntaxhighlight 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))))</langsyntaxhighlight>
 
===One-liner geek===
<langsyntaxhighlight lang="scala">for (i <- 1 to 100) println(Seq(15 -> "FizzBuzz", 3 -> "Fizz", 5 -> "Buzz").find(i % _._1 == 0).map(_._2).getOrElse(i))</langsyntaxhighlight>
 
===Functional Scala===
<syntaxhighlight lang ="scala">def fizzbuzzfizzBuzzTerm(l: List[String], n: Int, s): String) = if (l.head.toInt % n == 0) l :+ s else l
if (n % 15 == 0) "FizzBuzz"
def fizz(l: List[String]) = fizzbuzz(l, 3, "Fizz")
else if (n % 3 == 0) "Fizz"
def buzz(l: List[String]) = fizzbuzz(l, 5, "Buzz")
else if (n % 5 == 0) "Buzz"
def headOrTail(l: List[String]) = if (l.tail.size == 0) l.head else l.tail.mkString
else n.toString
Stream.from(1).take(100).map(n => List(n.toString)).map(fizz).map(buzz).map(headOrTail).foreach(println)</lang>
 
def fizzBuzz(): Unit = LazyList.from(1).take(100).map(fizzBuzzTerm).foreach(println)</syntaxhighlight>
 
===Scala 3 (Dotty)===
Written so as to introduce changes, with comments.
<syntaxhighlight lang="scala">def fizzBuzzTerm(n: Int): String | Int = // union types
(n % 3, n % 5) match // optional semantic indentation; no braces
case (0, 0) => "FizzBuzz"
case (0, _) => "Fizz"
case (_, 0) => "Buzz"
case _ => n // no need for `.toString`, thanks to union type
end match // optional `end` keyword, with what it's ending
end fizzBuzzTerm // `end` also usable for identifiers
 
val fizzBuzz = // no namespace object is required; all top level
LazyList.from(1).map(fizzBuzzTerm)
 
@main def run(): Unit = // @main for main method; can take custom args
fizzBuzz.take(100).foreach(println)</syntaxhighlight>
 
=={{header|Scheme}}==
<langsyntaxhighlight lang="scheme">(do ((i 1 (+ i 1)))
((> i 100))
(display
Line 6,041 ⟶ 10,368:
((= 0 (modulo i 5)) "Buzz")
(else i)))
(newline))</langsyntaxhighlight>
 
 
Using a recursive procedure.
<langsyntaxhighlight lang="scheme">(define (fizzbuzz x y)
(println
(cond (( = (modulo x 15) 0 ) "FizzBuzz")
Line 6,054 ⟶ 10,381:
(if (< x y) (fizzbuzz (+ x 1) y)))
 
(fizzbuzz 1 100)</langsyntaxhighlight>
 
Approach with maps and filters, easier to change, less readable
than the previous.
<syntaxhighlight lang="scheme">(define (fizzbuzz x)
(let ([words '((3 . "Fizz")
(5 . "Buzz"))])
(define (fbm x)
(let ([w (map cdr (filter (lambda (wo) (= 0 (modulo x (car wo)))) words))])
(if (null? w) x (apply string-append w))))
(for-each (cut format #t "~a~%" <>) (map fbm (iota x 1 1)))))
 
(fizzbuzz 15)
</syntaxhighlight>
 
=={{header|Sed}}==
<langsyntaxhighlight lang="sed">#n
# doesn't work if there's no input
# initialize counters (0 = empty) and value
Line 6,096 ⟶ 10,436:
# loop until value = 100
/100/q
b loop</langsyntaxhighlight>
 
Using <tt>seq</tt>:
<langsyntaxhighlight lang="sed">
seq 100 | sed '/.*[05]$/s//Buzz/;n;s//Buzz/;n;s//Buzz/;s/^[0-9]*/Fizz/'
</syntaxhighlight>
</lang>
 
=== GNU sed ===
Line 6,108 ⟶ 10,448:
Using <tt>seq</tt>:
 
<langsyntaxhighlight lang="sed">
seq 100 | sed '0~3 s/.*/Fizz/; 0~5 s/[0-9]*$/Buzz/'
</syntaxhighlight>
</lang>
 
Using <tt>yes</tt>:
<langsyntaxhighlight lang="sed">
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):
<langsyntaxhighlight lang="sed">
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>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 6,141 ⟶ 10,481:
end if;
end for;
end func;</langsyntaxhighlight>
 
=={{header|SenseTalk}}==
<syntaxhighlight lang="sensetalk">repeat 100
put "" into output
if the counter is a multiple of 3 then
put "Fizz" after output
end if
if the counter is a multiple of 5 then
put "Buzz" after output
end if
if output is empty then
put the counter into output
end if
put output
end repeat</syntaxhighlight>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program fizzbuzz;
loop for n in [1..100] do
print(fizzbuzz(n));
end loop;
 
proc fizzbuzz(n);
divs := [[3, "Fizz"], [5, "Buzz"]];
return +/[w : [d,w] in divs | n mod d=0] ? str n;
end proc;
end program;</syntaxhighlight>
 
=={{header|SequenceL}}==
 
<langsyntaxhighlight lang="sequencel">import <Utilities/Conversion.sl>;
import <Utilities/Sequence.sl>;
 
Line 6,160 ⟶ 10,527:
foreach i within 1 ... 100;
in
delimit(result, '\n');</langsyntaxhighlight>
 
=={{header|Shale}}==
 
<syntaxhighlight lang="shale">#!/usr/local/bin/shale
 
string library
 
r var
i var
i 1 =
{ i 100 <= } {
r "" =
i 3 % 0 == { r r "fizz" concat string::() = } ifthen
i 5 % 0 == { r r "buzz" concat string::() = } ifthen
r "" equals string::() { i } { r } if i "%3d: %p\n" printf
i++
} while</syntaxhighlight>
 
=={{header|Shen}}==
<langsyntaxhighlight Shenlang="shen">(define fizzbuzz
101 -> (nl)
N -> (let divisible-by? (/. A B (integer? (/ A B)))
Line 6,176 ⟶ 10,560:
(fizzbuzz (+ N 1))))))
 
(fizzbuzz 1)</langsyntaxhighlight>
 
=== Alternative showing off other features like prolog integration and guards ===
<syntaxhighlight lang="shen">(defprolog fizz
0 <-- (is _ (output "Fizz"));
N <-- (when (> N 0)) (is N1 (- N 3)) (fizz N1);
)
 
(defprolog buzz
0 <-- (is _ (output "Buzz"));
N <-- (when (> N 0)) (is N1 (- N 5)) (buzz N1);
)
 
(define none
[] -> true
[true | _] -> false
[_ | B] -> (none B)
)
 
(define fizzbuzz
N M -> (nl) where (> N M)
N M -> (do
(if (none [(prolog? (receive N) (fizz N)) (prolog? (receive N) (buzz N))])
(output (str N))
(output "!")
)
(nl)
(fizzbuzz (+ N 1) M)
)
)
 
(fizzbuzz 1 100)
</syntaxhighlight>
 
=={{header|Sidef}}==
Structured:
<langsyntaxhighlight rubylang="perl">{ |i|
if (i %% 3) {
print "Fizz"
Line 6,188 ⟶ 10,604:
elsif (i %% 5) { say "Buzz" }
else { say i }
} *<< 1..100</langsyntaxhighlight>
 
Declarative:
<langsyntaxhighlight rubylang="perl">func fizzbuzz({ _ %% 15 }) { "FizzBuzz" }
func fizzbuzz({ _ %% 5 }) { "Buzz" }
func fizzbuzz({ _ %% 3 }) { "Fizz" }
func fizzbuzz( n ) { n }
 
for n in (1..100) { say fizzbuzz(n) }</langsyntaxhighlight>
 
One-liner:
<langsyntaxhighlight lang="ruby">{|i|say >"#{<Fizz>[i.%3]}#{<Buzz>[i.%5]}"||i_}*<<1..100</langsyntaxhighlight>
 
=={{header|Simula}}==
<langsyntaxhighlight lang="simula">begin
integer i;
for i := 1 step 1 until 100 do
Line 6,216 ⟶ 10,632:
outimage
end;
end</langsyntaxhighlight>
 
=={{header|SkookumScript}}==
Answer by printing out one of the 4 alternatives:
<langsyntaxhighlight lang="javascript">
1.to 100
[
Line 6,229 ⟶ 10,645:
else [idx])
]
</syntaxhighlight>
</lang>
 
Answer by building up a string:
<langsyntaxhighlight lang="javascript">
1.to 100
[
Line 6,240 ⟶ 10,656:
println(if str.empty? [idx] else [str])
]
</syntaxhighlight>
</lang>
Or doing initial bind in one step:
<langsyntaxhighlight lang="javascript">
1.to 100
[
Line 6,250 ⟶ 10,666:
println(if str.empty? [idx] else [str])
]
</syntaxhighlight>
</lang>
 
=={{header|Slate}}==
<langsyntaxhighlight lang="slate">n@(Integer traits) fizzbuzz
[
output ::= ((n \\ 3) isZero ifTrue: ['Fizz'] ifFalse: ['']) ; ((n \\ 5) isZero ifTrue: ['Buzz'] ifFalse: ['']).
output isEmpty ifTrue: [n printString] ifFalse: [output]
].
1 to: 100 do: [| :i | inform: i fizzbuzz]</langsyntaxhighlight>
 
=={{header|Slope}}==
<syntaxhighlight lang="scheme">
(define fizz-buzz
(lambda (x)
(define ret "")
(if (zero? (% x 3))(set! ret (append ret "fizz")))
(if (zero? (% x 5))(set! ret (append ret "buzz")))
(if (equal? ret "") (set! ret (append ret x)))
ret))
(apply display-lines (list-join (map fizz-buzz (range 100 1))))
</syntaxhighlight>
 
=={{header|Small}}==
Line 6,265 ⟶ 10,693:
=={{header|Smalltalk}}==
Since only GNU Smalltalk supports file-based programming, we'll be using its syntax.
<langsyntaxhighlight lang="smalltalk">Integer extend [
fizzbuzz [
| fb |
Line 6,273 ⟶ 10,701:
]
]
1 to: 100 do: [ :i | i fizzbuzz displayNl ]</langsyntaxhighlight>
A Squeak/Pharo example using the Transcript window:
<langsyntaxhighlight lang="smalltalk">(1 to: 100) do:
[:n |
((n \\ 3)*(n \\ 5)) isZero
Line 6,283 ⟶ 10,711:
(n \\ 5) isZero
ifTrue: [Transcript show: 'Buzz'].
Transcript cr.]</langsyntaxhighlight>
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.
<langsyntaxhighlight lang="smalltalk">fizzbuzz := Dictionary with: #(true true)->'FizzBuzz'
with: #(true false)->'Fizz'
with: #(false true)->'Buzz'.
Line 6,292 ⟶ 10,720:
[ :i | Transcript show:
(fizzbuzz at: {i isDivisibleBy: 3. i isDivisibleBy: 5}
ifAbsent: [ i ]); cr]</langsyntaxhighlight>
Smalltalk does not have a case-select construct, but a similar effect can be attained using a collection and the #includes: method:
<langsyntaxhighlight lang="smalltalk">1 to: 100 do: [:n | |r|
r := n rem: 15.
Transcript show: (r isZero
Line 6,303 ⟶ 10,731:
ifTrue:['buzz']
ifFalse:[n]]]);
cr].</langsyntaxhighlight>
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):
<langsyntaxhighlight lang="smalltalk">fbz := (1 to: 100) asOrderedCollection.
3 to: 100 by: 3 do: [:i | fbz at: i put: 'Fizz'].
5 to: 100 by: 5 do: [:i | fbz at: i put: 'Buzz'].
15 to: 100 by: 15 do: [:i | fbz at: i put: 'FizzBuzz'].
fbz do: [:i | Transcript show: i; cr].</langsyntaxhighlight>
The approach building a dynamic string can be done as well:
<langsyntaxhighlight lang="smalltalk">1 to: 100 do: [:i | |fb s|
fb := {i isDivisibleBy: 3. i isDivisibleBy: 5. nil}.
fb at: 3 put: (fb first | fb second) not.
s := '<1?Fizz:><2?Buzz:><3?{1}:>' format: {i printString}.
Transcript show: (s expandMacrosWithArguments: fb); cr].</langsyntaxhighlight>
 
=={{header|SNOBOL4}}==
Merely posting a solution by Daniel Lyons
<langsyntaxhighlight lang="snobol4"> I = 1
LOOP FIZZBUZZ = ""
EQ(REMDR(I, 3), 0) :F(TRY_5)
Line 6,330 ⟶ 10,758:
I = I + 1
LE(I, 100) :S(LOOP)
END</langsyntaxhighlight>
 
=={{header|SNUSP}}==
See [[FizzBuzz/EsoLang]]
 
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "fizzbuzz" );
pragma annotate( description, "Write a program that prints the numbers from 1 to 100. But for multiples of" );
pragma annotate( description, "three print 'Fizz' instead of the number and for the multiples of five print" );
pragma annotate( description, "'Buzz'. For numbers which are multiples of both three and five print" );
pragma annotate( description, "'FizzBuzz'" );
pragma annotate( see_also, "http://rosettacode.org/wiki/FizzBuzz" );
pragma annotate( author, "Ken O. Burtch" );
pragma license( unrestricted );
 
pragma restriction( no_external_commands );
 
procedure fizzbuzz is
begin
for i in 1..100 loop
if i mod 15 = 0 then
? "FizzBuzz";
elsif i mod 5 = 0 then
? "Buzz";
elsif i mod 3 = 0 then
? "Fizz";
else
? i;
end if;
end loop;
end fizzbuzz;</syntaxhighlight>
 
=={{header|SQL}}==
{{libheader|SQL}}
===Oracle SQL===
<langsyntaxhighlight lang="sql">SELECT CASE
WHEN MOD(level,15)=0 THEN 'FizzBuzz'
WHEN MOD(level,3)=0 THEN 'Fizz'
Line 6,345 ⟶ 10,802:
END FizzBuzz
FROM dual
CONNECT BY LEVEL <= 100;</langsyntaxhighlight>
Or using Oracle's DECODE and NVL:
<langsyntaxhighlight lang="sql">SELECT nvl(decode(MOD(level,3),0,'Fizz')||decode(MOD(level,5),0,'Buzz'),level)
FROM dual
CONNECT BY level<=100;</langsyntaxhighlight>
 
===PostgreSQL specific===
<langsyntaxhighlight lang="sql">SELECT i, fizzbuzz
FROM
(SELECT i,
Line 6,362 ⟶ 10,819:
END AS fizzbuzz
FROM generate_series(1,100) AS i) AS fb
WHERE fizzbuzz IS NOT NULL;</langsyntaxhighlight>
 
Using Generate_Series and tables only:
<langsyntaxhighlight 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
FROM GENERATE_SERIES(1,100)) F LEFT JOIN
Line 6,371 ⟶ 10,828:
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
BUZZ.BUZZ_SERIES = F.FULL_SERIES;</langsyntaxhighlight>
 
===Recursive Common Table Expressions (MSSQL 2005+)===
<langsyntaxhighlight lang="sql">WITH nums (n, fizzbuzz ) AS (
SELECT 1, CONVERT(nvarchar, 1) UNION ALL
SELECT
Line 6,388 ⟶ 10,845:
SELECT n, fizzbuzz FROM nums
ORDER BY n ASC
OPTION ( MAXRECURSION 100 )</langsyntaxhighlight>
 
===SQL Anywhere specific - minimalist===
<syntaxhighlight lang="sql">SELECT
isnull(if row_num % 3 = 0 then 'Fizz' endif + if row_num % 5 = 0 then 'Buzz' endif, str(row_num))
FROM
sa_rowgenerator(1,100)</syntaxhighlight>
===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>.
<langsyntaxhighlight SQLlang="sql">-- Load some numbers
CREATE TABLE numbers(i INTEGER);
INSERT INTO numbers VALUES(1);
Line 6,414 ⟶ 10,877:
-- Tidy up
DROP TABLE fizzbuzz;
DROP TABLE numbers;</langsyntaxhighlight>
 
=={{header|Squirrel}}==
<langsyntaxhighlight lang="javascript">function Fizzbuzz(n) {
for (local i = 1; i <= n; i += 1) {
if (i % 15 == 0)
Line 6,430 ⟶ 10,893:
}
}
Fizzbuzz(100);</langsyntaxhighlight>
 
=={{header|Stata}}==
<langsyntaxhighlight lang="stata">program define fizzbuzz
args n
forvalues i = 1/`n' {
Line 6,449 ⟶ 10,912:
}
}
end</langsyntaxhighlight>
 
=={{header|Swahili}}==
<syntaxhighlight lang="swahili">
shughuli fizzBuzz() {
kwa i = 1 mpaka 100 {
kama (i % 15 == 0) {
andika("FizzBuzz")
} au (i % 5 == 0) {
andika("Buzz")
} au (i % 3 == 0) {
andika("Fizz")
} sivyo {
andika(i)
}
}
}
</syntaxhighlight>
 
=={{header|Swift}}==
=== using a switch statement ===
<lang swift>for i in 1...100 {
<syntaxhighlight lang="swift">for i in 1...100 {
switch (i % 3, i % 5) {
case (0, 0):
Line 6,463 ⟶ 10,944:
print(i)
}
}</langsyntaxhighlight>
=== using two if statements and an Optional ===
<syntaxhighlight lang="swift">for i in 1...100{
var s:String?
if i%3==0{s="Fizz"}
if i%5==0{s=(s ?? "")+"Buzz"}
print(s ?? i)
}</syntaxhighlight>
 
=== using a precomputed cycle ===
<syntaxhighlight lang="swift">
import Foundation
 
let formats: [String] = [
"%d",
"%d",
"fizz",
"%d",
"buzz",
"fizz",
"%d",
"%d",
"fizz",
"buzz",
"%d",
"fizz",
"%d",
"%d",
"fizzbuzz",
]
 
var count = 0
var index = 0
while count < 100 {
count += 1
print(String(format: formats[index], count))
index += 1
index %= 15
}
</syntaxhighlight>
 
=={{header|Symsyn}}==
<langsyntaxhighlight lang="symsyn">
| FizzBuzz
 
Line 6,489 ⟶ 11,009:
goif
endif
</syntaxhighlight>
</lang>
 
=={{header|Tailspin}}==
<syntaxhighlight lang="tailspin">
templates fizz
$ mod 3 -> #
when <=0> do 'Fizz' !
end fizz
 
templates buzz
$ mod 5 -> #
when <=0> do 'Buzz' !
end buzz
 
[ 1..100 -> '$->fizz;$->buzz;' ] -> \[i](when <=''> do $i ! otherwise $ !\)... -> '$;
' -> !OUT::write
</syntaxhighlight>
 
=={{header|tbas}}==
See [[FizzBuzz/Basic]]
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">proc fizzbuzz {n {m1 3} {m2 5}} {
for {set i 1} {$i <= $n} {incr i} {
set ans ""
Line 6,500 ⟶ 11,039:
}
}
fizzbuzz 100</langsyntaxhighlight>
The following example shows Tcl's substitution mechanism that allows to concatenate the results of two successive commands into a string:
<langsyntaxhighlight lang="tcl">while {[incr i] < 101} {
set fb [if {$i % 3 == 0} {list Fizz}][if {$i % 5 == 0} {list Buzz}]
if {$fb ne ""} {puts $fb} {puts $i}
}</langsyntaxhighlight>
This version uses list rotation, so avoiding an explicit mod operation:
<langsyntaxhighlight lang="tcl">set f [lrepeat 5 "Fizz" {$i} {$i}]
foreach i {5 10} {lset f $i "Buzz"};lset f 0 "FizzBuzz"
for {set i 1} {$i <= 100} {incr i} {
puts [subst [lindex [set f [list {*}[lassign $f ff] $ff]] 0]]
}</langsyntaxhighlight>
 
=={{header|TI SR-56}}==
 
{| class="wikitable"
|+ Texas Instruments SR-56 Program Listing for "Fizzbuzz"
|-
! Display !! Key !! Display !! Key !! Display !! Key !! Display !! Key
|-
| 00 22 || GTO || 25 64 || x || 50 03 || 3 || 75 ||
|-
| 01 03 || 3 || 26 52 || ( || 51 34 || RCL || 76 ||
|-
| 02 07 || 7 || 27 52 || ( || 52 01 || 1 || 77 ||
|-
| 03 53 || ) || 28 34 || RCL || 53 59 || *pause || 78 ||
|-
| 04 12 || INV || 29 01 || 1 || 54 22 || GTO || 79 ||
|-
| 05 29 || *Int || 30 54 || / || 55 03 || 3 || 80 ||
|-
| 06 56 || *CP || 31 05 || 5 || 56 08 || 8 || 81 ||
|-
| 07 12 || INV || 32 57 || subr || 57 || || 82 ||
|-
| 08 37 || *x=t || 33 00 || 0 || 58 || || 83 ||
|-
| 09 01 || 1 || 34 03 || 3 || 59 || || 84 ||
|-
| 10 03 || 3 || 35 94 || = || 60 || || 85 ||
|-
| 11 01 || 1 || 36 58 || rtn || 61 || || 86 ||
|-
| 12 84 || + || 37 38 || *CMs || 62 || || 87 ||
|-
| 13 00 || 0 || 38 01 || 1 || 63 || || 88 ||
|-
| 14 53 || ) || 39 35 || SUM || 64 || || 89 ||
|-
| 15 58 || rtn || 40 02 || 2 || 65 || || 90 ||
|-
| 16 33 || STO || 41 34 || RCL || 66 || || 91 ||
|-
| 17 01 || 1 || 42 02 || 2 || 67 || || 92 ||
|-
| 18 54 || / || 43 57 || subr || 68 || || 93 ||
|-
| 19 03 || 3 || 44 01 || 1 || 69 || || 94 ||
|-
| 20 57 || subr || 45 06 || 6 || 70 || || 95 ||
|-
| 21 00 || 0 || 46 93 || +/- || 71 || || 96 ||
|-
| 22 03 || 3 || 47 12 || INV || 72 || || 97 ||
|-
| 23 84 || + || 48 47 || *x>=t || 73 || || 98 ||
|-
| 24 02 || 2 || 49 05 || 5 || 74 || || 99 ||
|}
 
Asterisk denotes 2nd function key.
 
{| class="wikitable"
|+ Register allocation
|-
| 0: Unused || 1: Argument || 2: Number || 3: Unused || 4: Unused
|-
| 5: Unused || 6: Unused || 7: Unused || 8: Unused || 9: Unused
|}
 
Annotated listing:
<syntaxhighlight lang="text">
// Address 00: Entry point
 
GTO 3 7 // Jump to the main program
 
// Address 03: Subroutine
// Takes a pending division such as ((12/5 and evaluates whether it
// is evenly divisible.
// Result 1: evenly divisible, 0: not divisible
 
) // Complete the pending division
INV *Int // Take the fractional part
*CP // RegT := 0
INV *x=t 1 3 // If fractional part is zero, don't increment
1 + // Start a pending increment of the return value
0 ) rtn // Return the return value
 
// Address 16: Subroutine
// Takes a number and evaluates whether it is divisible by 3 and 5.
// Result: 0=indivisible, 1=fizz, 2=buzz, 3=fizzbuzz
 
STO 1 // Save subroutine argument
/ 3 subr 0 3 // 1 if fizz else 0
+ 2 x // Buzz is worth 2x as much as Fizz
( ( RCL 1 / 5 subr 0 3 // 1 if buzz else 0
= // Finish the pending + and x
rtn // Return result
 
// Address 37: Main program
 
*CMs // Zero out registers
1 SUM 2 // Number += 1
RCL 2 // Retrieve Number
subr 1 6 // Evaluate whether it is divisible by 3 and 5
+/- // Negate (0=indiv., -1=fizz, -2=buzz, -3=fizzbuzz)
INV *x>=t 5 3 // If negative, skip the next line.
RCL 1 // Retrieve number instead of zero.
*pause // Flash the number on the display
GTO 3 8 // Loop
</syntaxhighlight>
 
'''Usage:'''
 
Press RST R/S to start the program. Increasing numbers will flash on the screen. Positive numbers represent themselves; -1 means fizz, -2 buzz and -3 fizzbuzz. About 25 numbers are calculated per minute.
 
=={{header|TI-83 BASIC}}==
Line 6,518 ⟶ 11,171:
=={{header|TI-83 Hex Assembly}}==
See [[FizzBuzz/Assembly]]
 
=={{header|TI-99/4a TI BASIC / Extended BASIC}}==
See [[FizzBuzz/Basic]]
 
=={{Header|Tiny BASIC}}==
See [[FizzBuzz/Basic]]
 
=={{header|TransFORTH}}==
<langsyntaxhighlight lang="forth">: FIZZBUZZ
101 1 DO
I 15 MOD 0 = IF
Line 6,529 ⟶ 11,188:
PRINT " BUZZ "
ELSE I . THEN THEN THEN
CR LOOP ;</langsyntaxhighlight>
 
=={{header|TuringTrue BASIC}}==
See [[FizzBuzz/Basic]]
<lang Turing>setscreen("nocursor,noecho")
 
=={{header|Turing}}==
for i : 1 .. 100
<syntaxhighlight lang="turing">for i : 1 .. 100
if i mod 15 = 0 then
put "Fizzbuzz" ..
elsif i mod 5 = 0 then
put "Buzz" ..
elsif i mod 3 = 0 then
put "Fizz" ..
else
put i ..
end if
end for</langsyntaxhighlight>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
LOOP n=1,100
mod=MOD (n,15)
Line 6,560 ⟶ 11,220:
PRINT n
ENDSELECT
ENDLOOP</langsyntaxhighlight>
 
=={{header|TXR}}==
<langsyntaxhighlight 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))"</langsyntaxhighlight>
 
=={{header|UNIX Shell}}==
This solution should work with any Bourne-compatible shell: <!-- http://ideone.com/usJXGo -->
<langsyntaxhighlight lang="bash">i=1
while expr $i '<=' 100 >/dev/null; do
w=false
Line 6,574 ⟶ 11,234:
if $w; then echo; else echo $i; fi
i=`expr $i + 1`
done</langsyntaxhighlight>
 
===Versions for specific shells===
Line 6,580 ⟶ 11,240:
 
The next solution requires <code>$(( ))</code> arithmetic expansion,
whichand isit inshould work with every POSIX shell; but it also requires the <tt>seq(1)</tt> command, .
which is not part of some systems. <br>
(If your system misses <tt>seq(1)</tt>, but it has [[:Category:jot|BSD <tt>jot(1)</tt>]], then change <tt>`seq 1 100`</tt> to <tt>`jot 100`</tt>.)
<!-- http://ideone.com/5yZmOz -->
<syntaxhighlight lang ="bash">for n in `seq =1 100`; do
while [ if100 [-ge $((n % 15)) = 0 ]; thendo
if [ $((n % 15)) -eq 0 ]; then
echo FizzBuzz
elif [ $((n % 3)) =-eq 0 ]; then
echo Fizz
elif [ $((n % 5)) =-eq 0 ]; then
echo Buzz
else
echo $n
fi
n=$((n + 1))
done</lang>
done</syntaxhighlight>
 
The next solution requires the <code>(( ))</code> command from the [[Korn Shell]].
{{works with|pdksh|5.2.14}}
<langsyntaxhighlight lang="bash">NUM=1
until ((NUM == 101)) ; do
if ((NUM % 15 == 0)) ; then
Line 6,610 ⟶ 11,270:
fi
((NUM = NUM + 1))
done</langsyntaxhighlight>
 
A version using concatenation:
{{works with|bash|3}}
<langsyntaxhighlight lang="bash">for ((n=1; n<=100; n++))
do
fb=''
Line 6,620 ⟶ 11,280:
[ $(( n % 5 )) -eq 0 ] && fb="${fb}Buzz"
[ -n "${fb}" ] && echo "${fb}" || echo "$n"
done</langsyntaxhighlight>
 
A version using some of the insane overkill of Bash 4:
{{works with|bash|4}}
<langsyntaxhighlight lang="bash">command_not_found_handle () {
local Fizz=3 Buzz=5
[ $(( $2 % $1 )) -eq 0 ] && echo -n $1 && [ ${!1} -eq 3 ]
Line 6,633 ⟶ 11,293:
Fizz $i && ! Buzz $i || echo -n $i
echo
done</langsyntaxhighlight>
 
Bash one-liner: <!-- http://ideone.com/xMEGFK -->
<langsyntaxhighlight 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</langsyntaxhighlight>
 
==={{header|C Shell}}===
<langsyntaxhighlight lang="csh">@ n = 1
while ( $n <= 100 )
if ($n % 15 == 0) then
Line 6,651 ⟶ 11,311:
endif
@ n += 1
end</langsyntaxhighlight>
 
=={{header|Uiua}}==
<syntaxhighlight lang="Uiua">
⟨⟨⟨&p|&p"Fizz"◌⟩=0◿3.|&p"Buzz"◌⟩=0◿5.|&p"Fizzbuzz"◌⟩=0◿15.+1⇡100
</syntaxhighlight>
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa">#
# fizzbuzz
#
Line 6,669 ⟶ 11,334:
end if
out endl console
end for</langsyntaxhighlight>
 
=={{header|Ursala}}==
<langsyntaxhighlight Ursalalang="ursala">#import std
#import nat
 
Line 6,679 ⟶ 11,344:
#show+
 
main = fizzbuzz*t iota 101</langsyntaxhighlight>
 
=={{header|V}}==
<langsyntaxhighlight lang="v">[fizzbuzz
1 [>=] [
[[15 % zero?] ['fizzbuzz' puts]
Line 6,690 ⟶ 11,355:
] when succ
] while].
|100 fizzbuzz</langsyntaxhighlight>
 
===Second try===
Line 6,696 ⟶ 11,361:
 
define a command that will generate a sequence
<langsyntaxhighlight lang="v">[seq [] swap dup [zero? not] [rolldown [dup] dip cons rollup pred] while pop pop].</langsyntaxhighlight>
create a quote that will return a quote that returns a quote if its argument is an integer (A HOF)
<langsyntaxhighlight lang="v">[check [N X F : [[integer?] [[X % zero?] [N F cons] if] if]] view].</langsyntaxhighlight>
Create a quote that will make sure that the above quote is applied correctly if given (Number Function)
as arguments.
<langsyntaxhighlight lang="v">[func [[N F] : [dup N F check i] ] view map].</langsyntaxhighlight>
And apply it
<langsyntaxhighlight lang="v">100 seq [
[15 [pop 'fizzbuzz' puts]]
[5 [pop 'buzz' puts]]
[3 [pop 'fizz' puts]]
[1 [puts]]] [func dup] step
[i true] map pop</langsyntaxhighlight>
the first one is much better :)
 
=={{header|Vala}}==
<langsyntaxhighlight lang="vala">int main() {
for (int i = 1; i <= 100; i++) {
if (i % 3 == 0) stdout.printf("Fizz\n");
Line 6,721 ⟶ 11,386:
}
return 0;;
}</langsyntaxhighlight>
 
=={{header|Vale}}==
{{works with|Vale|0.2.0}}
<syntaxhighlight lang="vale">
import stdlib.*;
 
exported func main(){
fizzBuzz(1, 100);
}
 
func fizzBuzz(i int, stop int) {
result = if i.mod(3) == 0 {
"Fizz" } else { ""
} + if i.mod(5) == 0 {
"Buzz" } else { ""
};
 
println(if result == "" { i.str() } else { result });
 
if i < stop {
return fizzBuzz(i + 1, stop);
}
}
</syntaxhighlight>
 
=={{header|VAX Assembly}}==
<syntaxhighlight lang="vax assembly"> 00000008 0000 1 len =8
00000008 0000 2 msg: .blkb len ;output buffer
0000000C 0008 3 desc: .blkl 1 ;descriptor lenght field
00000000' 000C 4 .address msg ;pointer to buffer
00000012 0010 5 outlen: .blkw 1
4C 55 21 0000001A'010E0000' 0012 6 ctr: .ascid "!UL"
001D 7
0000 001D 8 .entry start,0
52 7C 001F 9 clrq r2 ;r2+r3 64bit
52 D6 0021 10 incl r2 ;start index 1
0023 11 loop:
E2 AF B4 0023 12 clrw desc ;assume not fizz and or buzz
55 D7 AF 9E 0026 13 movab msg, r5 ;pointer to message buffer
54 50 52 03 7B 002A 14 ediv #3,r2,r0,r4 ;divr.rl,divd.rq,quo.wl,rem.wl
54 D5 002F 15 tstl r4 ;remainder
0B 12 0031 16 bneq not_fizz ;not equal zero
0033 17
85 7A7A6966 8F D0 0033 18 movl #^a"fizz", (r5)+ ;add to message
CA AF 04 A0 003A 19 addw2 #4, desc ;and update length
003E 20 not_fizz:
54 50 52 05 7B 003E 21 ediv #5,r2,r0,r4
54 D5 0043 22 tstl r4
0B 12 0045 23 bneq not_buzz
0047 24
85 7A7A7562 8F D0 0047 25 movl #^a"buzz", (r5)+
B6 AF 04 A0 004E 26 addw2 #4, desc
0052 27 not_buzz:
B3 AF B5 0052 28 tstw desc ;fizz and or buzz?
1B 12 0055 29 bneq show_buffer ;neq - yes
0057 30
AD AF 08 B0 0057 31 movw #len, desc ;fao length limit
005B 32 $fao_s - ;eql -no
005B 33 ctrstr = ctr, - ;show number
005B 34 outlen = outlen, -
005B 35 outbuf = desc, -
005B 36 p1 = r2
96 AF A0 AF B0 006D 37 movw outlen, desc ;characters filled by fao
0072 38 show_buffer:
93 AF 7F 0072 39 pushaq desc
00000000'GF 01 FB 0075 40 calls #1, g^lib$put_output
9F 52 00000064 8F F3 007C 41 AOBLEQ #100,r2,loop ;limit.rl, index.ml
04 0084 42 ret
0085 43 .end start</syntaxhighlight>
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">
<lang vb>
Option Explicit
 
Line 6,731 ⟶ 11,465:
Dim i As Integer
For i = 1 To 100
'Tb(i) = i ' move to Else
If i Mod 15 = 0 Then
Tb(i) = "FizzBuzz"
ElseIf i Mod 3 = 0 Then
Tb(i) = "Fizz"
ElseIf i Mod 5 = 0 Then
Tb(i) = "Buzz"
ElseIf i Mod 3 = 0 Then
Tb(i) = "Fizz"
Else
Tb(i) = i
End If
Next
Debug.Print Join(Tb, vbCrLf)
End Sub</langsyntaxhighlight>
As an alternative, testing each number only once:
<syntaxhighlight lang="vb">
Sub FizzBuzz()
Dim i As Integer
Dim T(1 To 99) As Variant
For i = 1 To 99 Step 3
T(i + 0) = IIf((i + 0) Mod 5 = 0, "Buzz", i)
T(i + 1) = IIf((i + 1) Mod 5 = 0, "Buzz", i + 1)
T(i + 2) = IIf((i + 2) Mod 5 = 0, "FizzBuzz", "Fizz")
Next i
Debug.Print Join(T, ", ") & ", Buzz"
End Sub
</syntaxhighlight>
 
=={{header|VBScript}}==
{{works with|Windows Script Host|*}}
<langsyntaxhighlight VBScriptlang="vbscript">For i = 1 To 100
If i Mod 15 = 0 Then
WScript.Echo "FizzBuzz"
Line 6,755 ⟶ 11,504:
WScript.Echo i
End If
Next</langsyntaxhighlight>
 
=====An Alternative=====
{{works with|Windows Script Host|*}}
<langsyntaxhighlight VBScriptlang="vbscript">With WScript.StdOut
For i = 1 To 100
If i Mod 3 = 0 Then .Write "Fizz"
Line 6,765 ⟶ 11,514:
If .Column = 1 Then .WriteLine i Else .WriteLine ""
Next
End With</langsyntaxhighlight>
 
=={{header|Verbexx}}==
<langsyntaxhighlight Verbexxlang="verbexx">@LOOP init:{@VAR t3 t5; @VAR i = 1} while:(i <= 100) next:{i++}
{
t3 = (i % 3 == 0);
Line 6,778 ⟶ 11,527:
else: { i }
);
};</langsyntaxhighlight>
 
 
=={{header|Verilog}}==
<syntaxhighlight lang="verilog">
module main;
integer number;
initial begin
 
for(number = 1; number < 100; number = number + 1) begin
if (number % 15 == 0) $display("FizzBuzz");
else begin
if(number % 3 == 0) $display("Fizz");
else begin
if(number % 5 == 0) $display("Buzz");
else $display(number);
end
end
end
$finish;
end
endmodule
</syntaxhighlight>
 
 
=={{header|VHDL}}==
<syntaxhighlight lang="vhdl">entity fizzbuzz is
end entity fizzbuzz;
 
architecture beh of fizzbuzz is
 
procedure fizzbuzz(num : natural) is
begin
if num mod 15 = 0 then
report "FIZZBUZZ";
elsif num mod 3 = 0 then
report "FIZZ";
elsif num mod 5 = 0 then
report "BUZZ";
else
report to_string(num);
end if;
end procedure fizzbuzz;
 
begin
 
p_fizz : process is
begin
for i in 1 to 100 loop
fizzbuzz(i);
end loop;
wait for 200 us;
end process p_fizz;
 
end architecture beh;</syntaxhighlight>
 
=={{header|Vim Script}}==
<langsyntaxhighlight lang="vim">for i in range(1, 100)
if i % 15 == 0
echo "FizzBuzz"
Line 6,791 ⟶ 11,595:
echo i
endif
endfor</langsyntaxhighlight>
 
=={{header|Visual Basic .NET}}==
Line 6,797 ⟶ 11,601:
 
=={{header|Visual Prolog}}==
<syntaxhighlight lang="text">
implement main
open core, console
Line 6,820 ⟶ 11,624:
goal
console::runUtf8(main::run).
</syntaxhighlight>
</lang>
 
=={{header|V (Vlang)}}==
Updated for V (Vlang) version 0.2.2
<syntaxhighlight lang="go">const (
fizz = Tuple{true, false}
buzz = Tuple{false, true}
fizzbuzz = Tuple{true, true}
)
 
struct Tuple{
val1 bool
val2 bool
}
 
fn fizz_or_buzz( val int ) Tuple {
return Tuple{ val % 3 == 0, val % 5 == 0 }
}
 
fn fizzbuzz( n int ) {
for i in 1..(n + 1) {
match fizz_or_buzz(i) {
fizz { println('Fizz') }
buzz { println('Buzz') }
fizzbuzz { println('FizzBuzz') }
else { println(i) }
}
}
}
 
fn main(){
fizzbuzz(15)
}
</syntaxhighlight>
{{out}}
<pre>1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
</pre>
 
Basic example with a for loop and match:
 
<syntaxhighlight lang="go">
fn main() {
mut i := 1
for i <= 100 {
match true {
i % 15 == 0 { println('FizzBuzz') }
i % 3 == 0 { println('Fizz') }
i % 5 == 0 { println('Buzz') }
else { println(i) }
}
i++
}
}
</syntaxhighlight>
 
Another basic example using the ubiquitous if/else (if) statement:
 
<syntaxhighlight lang="go">
fn main() {
for i in 1..100 {
if i % 15 == 0 {
println('FizzBuzz')
} else if i % 3 == 0 {
println('Fizz')
} else if i % 5 == 0 {
println('Buzz')
} else {
println(i)
}
}
}
</syntaxhighlight>
{{out}}
<pre style="height:40ex">
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>
 
=={{header|VTL-2}}==
<syntaxhighlight lang="vtl2">10 N=1
20 #=30
30 #=N/3*0+%=0*110
40 #=N/5*0+%=0*130
50 #=!+30
60 ?=N
70 ?=""
80 N=N+1
90 #=100>N*20
100 #=999
110 ?="Fizz";
120 #=!
130 ?="Buzz";
140 #=!
180 #=70</syntaxhighlight>
 
=={{header|Wart}}==
<langsyntaxhighlight lang="wart">for i 1 (i <= 100) ++i
prn (if (divides i 15)
"FizzBuzz"
Line 6,831 ⟶ 11,840:
"Buzz"
:else
i)</langsyntaxhighlight>
 
=={{header|WDTE}}==
<langsyntaxhighlight WDTElang="wdte">'let io' => import 'io';
let s => import 'stream';
'stream' => s;
 
let multiple of n => == (% n of) 0;
 
let fizzbuzz n => switch n {
multiple (* 3 5) => 'FizzBuzz';
multiple 3 => 'Fizz';
Line 6,846 ⟶ 11,855:
} -- io.writeln io.stdout;
 
main => s.range 1 101 -> s.map fizzbuzz -> s.drain;</langsyntaxhighlight>
 
=={{header|Whitespace}}==
Line 6,852 ⟶ 11,861:
 
=={{header|Wortel}}==
<langsyntaxhighlight lang="wortel">@each &x!console.log x !*&x?{%%x 15 "FizzBuzz" %%x 5 "Buzz" %%x 3 "Fizz" x} @to 100</langsyntaxhighlight>
 
=={{header|Wren}}==
<syntaxhighlight lang="wren">for (i in 1..100) {
if (i % 15 == 0) {
System.print("FizzBuzz")
} else if (i % 3 == 0) {
System.print("Fizz")
} else if (i % 5 == 0) {
System.print("Buzz")
} else {
System.print(i)
}
}</syntaxhighlight>
 
{{out}}
<pre style="height:40ex">
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>
 
=={{header| X86 Assembly}}==
<langsyntaxhighlight lang="x86asm">
; x86_64 linux nasm
 
Line 6,960 ⟶ 12,086:
syscall
ret
</syntaxhighlight>
</lang>
 
=={{header|XBasic}}==
See [[FizzBuzz/Basic]]
 
=={{header|XLISP}}==
<langsyntaxhighlight lang="lisp">(defun fizzbuzz ()
(defun fizzb (x y)
(display (cond
Line 6,975 ⟶ 12,104:
(fizzb 1 100))
 
(fizzbuzz)</langsyntaxhighlight>
 
=={{header|XMIDAS}}==
<langsyntaxhighlight XMIDASlang="xmidas">startmacro
loop 100 count
calc/quiet three ^count 3 modulo
Line 6,992 ⟶ 12,121:
endif
endloop
endmacro</langsyntaxhighlight>
 
=={{header|Xojo}}==
<syntaxhighlight lang="vb"> For i As Integer = 1 To 100
If i Mod 3 = 0 And i Mod 5 = 0 Then
Print("FizzBuzz")
ElseIf i Mod 3 = 0 Then
Print("Fizz")
ElseIf i Mod 5 = 0 Then
Print("Buzz")
Else
Print(Str(i))
End If
Next</syntaxhighlight>
An alternative syntax:
<syntaxhighlight lang="vb">
For i As Integer = 1 To 100
Select Case True
Case i Mod 3 = 0 And i Mod 5 = 0
Print("FizzBuzz")
Case i Mod 3 = 0
Print("Fizz")
Case i Mod 5 = 0
Print("Buzz")
Else
Print(Str(i))
End Select
Next</syntaxhighlight>
 
=={{header|XPath 2.0}}==
<langsyntaxhighlight XPathlang="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)])</langsyntaxhighlight>
...or alternatively...
<langsyntaxhighlight XPathlang="xpath">for $n in 1 to 100 return
($n, 'Fizz', 'Buzz', 'FizzBuzz')[number(($n mod 3) = 0) + number(($n mod 5) = 0)*2 + 1]</langsyntaxhighlight>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">code CrLf=9, IntOut=11, Text=12;
int N;
[for N:= 1 to 100 do
Line 7,010 ⟶ 12,166:
CrLf(0);
];
]</langsyntaxhighlight>
{{out}}
<pre>
Line 7,038 ⟶ 12,194:
===XSLT 1.0===
{{works with|xsltproc|libxslt 10126}}
<langsyntaxhighlight lang="xml"><?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="utf-8"/>
Line 7,090 ⟶ 12,246:
<xsl:call-template name="fizzbuzz-range"/>
</xsl:template>
</xsl:stylesheet></langsyntaxhighlight>
===XSLT 1.0 With EXSLT===
<langsyntaxhighlight lang="xml"><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
Line 7,124 ⟶ 12,280:
</xsl:template>
</xsl:stylesheet></langsyntaxhighlight>
 
===XSLT 2.0===
<langsyntaxhighlight lang="xml"><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
 
Line 7,136 ⟶ 12,292:
</xsl:template>
 
</xsl:stylesheet></langsyntaxhighlight>
 
 
=={{header|Yabasic}}==
See [[FizzBuzz/Basic]]
 
 
=={{header|YAMLScript}}==
 
<syntaxhighlight lang="yaml">
#!/usr/bin/env ys-0
 
# This program has multiple implementations of "fizzbuzz".
 
# usage: yamlscript fizzbuzz.ys [<count>] [<fizzbuzz-fn-#>]
 
# The main function runs a certain requested fizzbuzz implementation function
# for a certain requested number (default is 100).
 
defn main(count=100 impl=1):
fizzbuzz =: "fizzbuzz-$impl"
 
when-not ENV.'YS_TEST':
say: "Running function '$fizzbuzz' with count=$count"
 
function =: resolve(fizzbuzz.symbol())
result =: function(count)
 
mapv say: result
 
 
# These implementation functions were adapted from
# https://rosettacode.org/wiki/FizzBuzz#Clojure
 
defn fizzbuzz-1(n):
map:
fn(x):
cond:
zero?(x % 15): 'FizzBuzz'
zero?(x % 5): 'Buzz'
zero?(x % 3): 'Fizz'
=>: x
=>: 1 .. n
 
defn fizzbuzz-2(n):
loop [i 1, l []]:
if (i > n):
=>: l
recur inc(i):
conj l:
cond:
zero?(i % 15): 'FizzBuzz'
zero?(i % 5): 'Buzz'
zero?(i % 3): 'Fizz'
=>: i
 
defn fizzbuzz-3(n):
map:
fn(x):
s =:
str:
when zero?(x % 3): 'Fizz'
=>: (zero?(x % 5) && 'Buzz') || nil
if empty?(s): x s
rng: 1 n
</syntaxhighlight>
{{out}}
<pre>
$ ys sample/fizzbuzz.ys 16 2
Running function 'fizzbuzz-2' with count=16
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
</pre>
 
=={{header|Yorick}}==
===Iterative solution===
<langsyntaxhighlight lang="yorick">for(i = 1; i <= 100; i++) {
if(i % 3 == 0)
write, format="%s", "Fizz";
Line 7,148 ⟶ 12,390:
write, format="%d", i;
write, "";
}</langsyntaxhighlight>
===Vectorized solution===
<langsyntaxhighlight lang="yorick">output = swrite(format="%d", indgen(100));
output(3::3) = "Fizz";
output(5::5) = "Buzz";
output(15::15) = "FizzBuzz";
write, format="%s\n", output;</langsyntaxhighlight>
 
=={{header|Z80 Assembly}}==
See [[FizzBuzz/Assembly]]
 
=={{header|Zig}}==
<syntaxhighlight lang="zig">const print = @import("std").debug.print;
pub fn main() void {
var i: usize = 1;
while (i <= 100) : (i += 1) {
if (i % 3 == 0 and i % 5 == 0) {
print("FizzBuzz\n", .{});
} else if (i % 3 == 0) {
print("Fizz\n", .{});
} else if (i % 5 == 0) {
print("Buzz\n", .{});
} else {
print("{}\n", .{i});
}
}
}</syntaxhighlight>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">foreach n in ([1..100]) {
if(n % 3 == 0) print("Fizz");
if(not (n%5)) "Buzz".print();
if(n%3 and n%5) print(n);
println();
}</langsyntaxhighlight>
Or, using infinite lazy sequences:
<langsyntaxhighlight lang="zkl">fcn f(a,b,c){ a+b and a+b or c }
Walker.cycle("","","Fizz").zipWith(f,Walker.cycle("","","","","Buzz"),[1..])
.walk(100).concat("\n").println();</langsyntaxhighlight>
More of the same:
<langsyntaxhighlight 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();</langsyntaxhighlight>
{{out}}
<pre>
Line 7,195 ⟶ 12,454:
=={{header|ZX Spectrum Basic}}==
{{trans|Applesoft BASIC}}
<langsyntaxhighlight lang="zxbasic">10 DEF FN m(a,b)=a-INT (a/b)*b
20 FOR a=1 TO 100
30 LET o$=""
Line 7,202 ⟶ 12,461:
60 IF o$="" THEN LET o$=STR$ a
70 PRINT o$
80 NEXT a</langsyntaxhighlight>
1

edit