FizzBuzz

From Rosetta Code
Task
FizzBuzz
You are encouraged to solve this task according to the task description, using any language you may know.
Task

Write a program that prints the integers from   1   to   100   (inclusive).


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)


The   FizzBuzz   problem was presented as the lowest level of comprehension required to illustrate adequacy.


Also see



11l[edit]

Translation of: Python3: Simple
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)

360 Assembly[edit]

See FizzBuzz/Assembly

6502 Assembly[edit]

See FizzBuzz/Assembly

68000 Assembly[edit]

See FizzBuzz/Assembly

8080 Assembly[edit]

See FizzBuzz/Assembly

8086 Assembly[edit]

See FizzBuzz/Assembly

8th[edit]

with: n

: num?  \ n f --   ) 
	if drop else . then ;

\ is m mod n 0? leave the result twice on the stack
: div? \ m n -- f f
	mod 0 = dup ;

: fizz? \ n -- n f
	dup 3 
	div? if "Fizz" .  then ;

: buzz? \ n f -- n f
	over 5 
	div? if "Buzz" .  then or ;

\ print a message as appropriate for the given number:
: fizzbuzz  \ n --
	fizz? buzz? num? 
	space ;

\ iterate from 1 to 100:
' fizzbuzz 1 100 loop 
cr bye

AArch64 Assembly[edit]

Works with: as version Raspberry Pi 3B version Buster 64 bits
/* 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"

ABAP[edit]

Impure Functional 1[edit]

Works with: ABAP version 7.4 SP05 or Above only
DATA: tab TYPE TABLE OF string.

tab = VALUE #(
  FOR i = 1 WHILE i <= 100 (
    COND string( LET r3 = i MOD 3
                     r5 = i MOD 5 IN
                 WHEN r3 = 0 AND r5 = 0 THEN |FIZZBUZZ|
                 WHEN r3 = 0            THEN |FIZZ|
                 WHEN r5 = 0            THEN |BUZZ|
                 ELSE i ) ) ).

cl_demo_output=>write( tab ).
cl_demo_output=>display( ).

Impure Functional 2[edit]

Works with: ABAP version 7.4 SP05 or Above only
cl_demo_output=>display( value stringtab( for i = 1 until i > 100
                                          let fizz = cond #( when i mod 3 = 0 then |fizz| else space )
                                              buzz = cond #( when i mod 5 = 0 then |buzz| else space )
                                              fb   = |{ fizz }{ buzz }| in
                                         ( switch #( fb when space then i else fb ) ) ) ).

ACL2[edit]

(defun fizzbuzz-r (i)
   (declare (xargs :measure (nfix (- 100 i))))
   (prog2$
    (cond ((= (mod i 15) 0) (cw "FizzBuzz~%"))
          ((= (mod i 5) 0) (cw "Buzz~%"))
          ((= (mod i 3) 0) (cw "Fizz~%"))
          (t (cw "~x0~%" i)))
    (if (zp (- 100 i))
        nil
        (fizzbuzz-r (1+ i)))))

(defun fizzbuzz () (fizzbuzz-r 1))

Action![edit]

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
Output:

Screenshot from Atari 8-bit computer

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

ActionScript[edit]

The ActionScript solution works just like the JavaScript solution (they share the ECMAScript specification). The difference is that ActionScript has the trace command to write out to a console.

for (var i:int = 1; i <= 100; i++) {
  if (i % 15 == 0)
    trace('FizzBuzz');
  else if (i % 5 == 0)
    trace('Buzz');
  else if (i % 3 == 0)
    trace('Fizz');
  else
    trace(i);
}

Ada[edit]

with Ada.Text_IO; use Ada.Text_IO;
 
procedure Fizzbuzz is
begin
   for I in 1..100 loop
      if I mod 15 = 0 then
         Put_Line("FizzBuzz");
      elsif I mod 5 = 0 then
         Put_Line("Buzz");
      elsif I mod 3 = 0 then
         Put_Line("Fizz");
      else
         Put_Line(Integer'Image(I));
      end if;
   end loop;
end Fizzbuzz;


Agda[edit]

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

ALGOL 68[edit]

main:(
  FOR i TO 100 DO
    printf(($gl$,
      IF i %* 15 = 0 THEN
        "FizzBuzz"
      ELIF i %* 3 = 0 THEN
        "Fizz"
      ELIF i %* 5 = 0 THEN
        "Buzz"
      ELSE
        i
      FI
    ))
  OD
)

or simply:

FOR i TO 100 DO print(((i%*15=0|"FizzBuzz"|:i%*3=0|"Fizz"|:i%*5=0|"Buzz"|i),new line)) OD

ALGOL-M[edit]

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

ALGOL W[edit]

begin
    i_w := 1; % set integers to print in minimum space %
    for i := 1 until 100 do begin
        if      i rem 15 = 0 then write( "FizzBuzz" )
        else if i rem  5 = 0 then write( "Buzz" )
        else if i rem  3 = 0 then write( "Fizz" )
        else                      write( i )
    end for_i
end.

AntLang[edit]

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

APEX[edit]

for(integer i=1; i <= 100; i++){
    String output = '';
    if(math.mod(i, 3) == 0) output += 'Fizz';
    if(math.mod(i, 5) == 0) output += 'Buzz';
    if(output != ''){
        System.debug(output);
    } else {
        System.debug(i);
    }
}

APL[edit]

⎕IO0
(L,'Fizz' 'Buzz' 'FizzBuzz')[¯1+(L×W=0)+W(100×~0=W)+W⊃+/1 2×0=3 5|⊂L1+⍳100]


Slightly different approach that makes use of the Decode function (⊥):

A[I]1+I(0A)/⍳⍴A('FIZZBUZZ' 'FIZZ’ 'BUZZ' 0)[2¨×(3 5)|¨1+⍳100]

The idea is to first calculate the residues for all numbers 1..100 after division with both 3 and 5. This generates 100 pairs of numbers a b, where a is either 0,1,2 and b is either 0,1,2,3,4.

These pairs are then put through the sign function which returns 0 for a 0, and a 1 for anything greater than 0. Now we have binary pairs. The binary pairs are encoded with a left argument of 2 resulting in 0,1,2,3. These are treated as indices for the "FizzBuzz vector" where 0 is in position 3.

Variable A holds this new vector of words and zeros. Variable I is assigned the zeros' positions. Finally A[I] is replaced with corresponding indices.

If you have an aversion against mixed vectors, consider inserting ⍕¨ before the final (i.e. left-most) assignment.

Works with: Dyalog_APL

Here's a Dyalog-specific solution taking advantage of its anonymous function extension:

{  'Fizz' 'Buzz' 'FizzBuzz'[ +/1 2×0=3 5|] }¨1+⍳100

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):

{(FizzBuzz Fizz Buzz,)[(0=15 3 5|)1]}¨100

Yet another solution, excessively commented:

Works with: GNU_APL
(and Dyalog, with ⎕ML ← 2)
     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]   tn   ⍝ 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]  d1+(+  {((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
    

AppleScript[edit]

Procedural[edit]

property outputText: ""
repeat with i from 1 to 100
  if i mod 15 = 0 then
    set outputText to outputText & "FizzBuzz"
  else if i mod 3 = 0 then
    set outputText to outputText & "Fizz"
  else if i mod 5 = 0 then
    set outputText to outputText & "Buzz"
  else
    set outputText to outputText & i
  end if
  set outputText to outputText & linefeed
end repeat
outputText

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 (i mod … = 0) tests could be nested to reduce the number of these performed from 261 to 200:

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)

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:

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)

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[edit]

For simplicity, and more efficient use of the scripter's time:

------------------------- FIZZBUZZ -------------------------

-- fizz :: Int -> Bool
on fizz(n)
    n mod 3 = 0
end fizz

-- buzz :: Int -> Bool
on buzz(n)
    n mod 5 = 0
end buzz

-- fizzAndBuzz :: Int -> Bool
on fizzAndBuzz(n)
    n mod 15 = 0
end fizzAndBuzz

-- fizzBuzz :: Int -> String
on fizzBuzz(x)
    caseOf(x, [[my fizzAndBuzz, "FizzBuzz"], ¬
        [my fizz, "Fizz"], ¬
        [my buzz, "Buzz"]], x as string)
end fizzBuzz


--------------------------- TEST ---------------------------
on run
    
    intercalate(linefeed, ¬
        map(fizzBuzz, enumFromTo(1, 100)))
    
end run


-------------------- GENERIC FUNCTIONS ---------------------

-- caseOf :: a -> [(predicate, b)] -> Maybe b -> Maybe b
on caseOf(e, lstPV, default)
    repeat with lstCase in lstPV
        set {p, v} to contents of lstCase
        if mReturn(p)'s |λ|(e) then return v
    end repeat
    return default
end caseOf


-- enumFromTo :: Int -> Int -> [Int]
on enumFromTo(m, n)
    if m > n then
        set d to -1
    else
        set d to 1
    end if
    set lst to {}
    repeat with i from m to n by d
        set end of lst to i
    end repeat
    return lst
end enumFromTo


-- intercalate :: Text -> [Text] -> Text
on intercalate(strText, lstText)
    set {dlm, my text item delimiters} to {my text item delimiters, strText}
    set strJoined to lstText as text
    set my text item delimiters to dlm
    return strJoined
end intercalate


-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
    tell mReturn(f)
        set lng to length of xs
        set lst to {}
        repeat with i from 1 to lng
            set end of lst to |λ|(item i of xs, i, xs)
        end repeat
        return lst
    end tell
end map


-- Lift 2nd class handler function into 1st class script wrapper 
-- mReturn :: Handler -> Script
on mReturn(f)
    if class of f is script then
        f
    else
        script
            property |λ| : f
        end script
    end if
end mReturn

Applesoft BASIC[edit]

See FizzBuzz/Basic

Arbre[edit]

fizzbuzz():
  for x in [1..100]
    if x%5==0 and x%3==0
      return "FizzBuzz"
    else
      if x%3==0
        return "Fizz"
      else
        if x%5==0
          return "Buzz"
        else
           return x

main():
  fizzbuzz() -> io

Arc[edit]

Arc 3.1 Base[edit]

(for n 1 100
  (prn:if
    (multiple n 15) 'FizzBuzz
    (multiple n 5) 'Buzz
    (multiple n 3) 'Fizz
    n))
(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

Waterhouse Arc[edit]

(for n 1 100
  (prn:case (gcd n 15)
    1 n
    3 'Fizz
    5 'Buzz
      'FizzBuzz))

ARM Assembly[edit]

/ * 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

Arturo[edit]

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
]
Output:
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

AsciiDots[edit]

See FizzBuzz/EsoLang#AsciiDots

ASIC[edit]

See FizzBuzz/Basic

Asymptote[edit]

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);
           }
        }
    }
}

ATS[edit]

#include "share/atspre_staload.hats"

implement main0() = loop(1, 100) where {
  fun loop(from: int, to: int): void =
    if from > to then () else
    let
      val by3 = (from % 3 = 0)
      val by5 = (from % 5 = 0)
    in
      case+ (by3, by5) of
      | (true, true) => print_string("FizzBuzz")
      | (true, false) => print_string("Fizz")
      | (false, true) => print_string("Buzz")
      | (false, false) => print_int(from);
      print_newline();
      loop(from+1, to)
    end
}

AutoHotkey[edit]

Search autohotkey.com: [1]

Loop, 100
{
  If (Mod(A_Index, 15) = 0)
    output .= "FizzBuzz`n"
  Else If (Mod(A_Index, 3) = 0)
    output .= "Fizz`n"
  Else If (Mod(A_Index, 5) = 0)
    output .= "Buzz`n"
  Else
    output .= A_Index "`n"
}
FileDelete, output.txt
FileAppend, %output%, output.txt
Run, cmd /k type output.txt

A short example with cascading ternary operators and graphical output. Press Esc to close the window.

Gui, Add, Edit, r20
Gui,Show
Loop, 100
  Send, % (!Mod(A_Index, 15) ? "FizzBuzz" : !Mod(A_Index, 3) ? "Fizz" : !Mod(A_Index, 5) ? "Buzz" : A_Index) "`n"
Return
Esc::
ExitApp

AutoIt[edit]

Example1[edit]

Output via MsgBox():

For $i = 1 To 100
	If Mod($i, 15) = 0 Then
		MsgBox(0, "FizzBuzz", "FizzBuzz")
	ElseIf Mod($i, 5) = 0 Then
		MsgBox(0, "FizzBuzz", "Buzz")
	ElseIf Mod($i, 3) = 0 Then
		MsgBox(0, "FizzBuzz", "Fizz")
	Else
		MsgBox(0, "FizzBuzz", $i)
	EndIf
Next

Example2[edit]

Output via console, logfile and/or messagebox:

#include <Constants.au3>

; uncomment how you want to do the output
Func Out($Msg)
	ConsoleWrite($Msg & @CRLF)

;~	FileWriteLine("FizzBuzz.Log", $Msg)

;~ 	$Btn = MsgBox($MB_OKCANCEL + $MB_ICONINFORMATION, "FizzBuzz", $Msg)
;~ 	If $Btn > 1 Then Exit	; Pressing 'Cancel'-button aborts the program
EndFunc   ;==>Out

Out("# FizzBuzz:")
For $i = 1 To 100
	If Mod($i, 15) = 0 Then
		Out("FizzBuzz")
	ElseIf Mod($i, 5) = 0 Then
		Out("Buzz")
	ElseIf Mod($i, 3) = 0 Then
		Out("Fizz")
	Else
		Out($i)
	EndIf
Next
Out("# Done.")

Avail[edit]

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";
];

AWK[edit]

See FizzBuzz/AWK

Axe[edit]

For(I,1,100)
!If I^3??I^5
 Disp "FIZZBUZZ",i
Else!If I^3
 Disp "FIZZ",i
Else!If I^5
 Disp "BUZZ",i
Else
 Disp I▶Dec,i
End
.Pause to allow the user to actually read the output
Pause 1000
End

Babel[edit]

main: 
     { { iter 1 + dup
        
        15 %
            { "FizzBuzz" << 
                zap }
            { dup
            3 % 
                { "Fizz" << 
                    zap }
                { dup
                5 % 
                    { "Buzz" << 
                        zap}
                    { %d << }
                if }
            if }
        if

        "\n" << }

    100 times }

BaCon[edit]

See FizzBuzz/Basic#BaCon

bash[edit]

Any bash hacker would do this as a one liner at the shell, so...

for n in {1..100}; do ((( n % 15 == 0 )) && echo 'FizzBuzz') || ((( n % 5 == 0 )) && echo 'Buzz') || ((( n % 3 == 0 )) && echo 'Fizz') || echo $n; done

For the sake of readability...

for n in {1..100}; do
  ((( n % 15 == 0 )) && echo 'FizzBuzz') ||
  ((( n % 5 == 0 )) && echo 'Buzz') ||
  ((( n % 3 == 0 )) && echo 'Fizz') ||
  echo $n;
done

Here's a very concise approach, with only 75 characters total. Unfortunately it relies on aspects of Bash which are rarely used.

for i in {1..100};do((i%3))&&x=||x=Fizz;((i%5))||x+=Buzz;echo ${x:-$i};done

Here's the concise approach again, this time separated into multiple lines.

# 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...
        x= ||     # ...blank out x (yes, "x= " does that).  Otherwise,...
        x=Fizz    # ...set (not append) x to the string "Fizz".
    ((i % 5)) ||  # If i is not divisible by 5, skip (there's no "&&")...
        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

It's a bit silly to optimize such a small & fast program, but for the sake of algorithm analysis it's worth noting that the concise approach is reasonably efficient in several ways. Each divisibility test appears in the code exactly once, only two variables are created, and the approach avoids setting variables unnecessarily. As far as I can tell, the divisibility tests only fire the minimum number of times required for the general case (e.g. where the 100/3/5 constants can be changed), unless you introduce more variables and test types. Corrections invited. I avoided analyzing the non-general case where 100/3/5 never change, because one "optimal" solution is to simply print the pre-computed answer,

BASIC[edit]

See FizzBuzz/Basic

Basic09[edit]

See FizzBuzz/Basic

BASIC256[edit]

See FizzBuzz/Basic

Batch File[edit]

FOR /L version:

@echo off
for /L %%i in (1,1,100) do call :tester %%i
goto :eof

:tester
  set /a test = %1 %% 15
  if %test% NEQ 0 goto :NotFizzBuzz
  echo FizzBuzz
  goto :eof

:NotFizzBuzz
  set /a test = %1 %% 5
  if %test% NEQ 0 goto :NotBuzz
  echo Buzz
  goto :eof

:NotBuzz
  set /a test = %1 %% 3
  if %test% NEQ 0 goto :NotFizz
  echo Fizz
  goto :eof

:NotFizz
  echo %1

Loop version:

@echo off
set n=1

:loop
  call :tester %n%
  set /a n += 1
  if %n% LSS 101 goto loop
  goto :eof

:tester
  set /a test = %1 %% 15
  if %test% NEQ 0 goto :NotFizzBuzz
  echo FizzBuzz
  goto :eof

:NotFizzBuzz
  set /a test = %1 %% 5
  if %test% NEQ 0 goto :NotBuzz
  echo Buzz
  goto :eof

:NotBuzz
  set /a test = %1 %% 3
  if %test% NEQ 0 goto :NotFizz
  echo Fizz
  goto :eof

:NotFizz
  echo %1

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

@echo off & setlocal enabledelayedexpansion
for /l %%i in (1,1,100) do (
  set /a m5=%%i %% 5
  set /a m3=%%i %% 3
  set s=
  if !m5! equ 0 set s=!s!Fizz
  if !m3! equ 0 set s=!s!Buzz
  if "!s!"=="" set s=%%i
  echo !s!
)

BBC BASIC[edit]

See FizzBuzz/Basic

bc[edit]

This solution never uses else, because bc has no else keyword (but some implementations add else as an extension).

for (i = 1; i <= 100; i++) {
	w = 0
	if (i % 3 == 0) { "Fizz"; w = 1; }
	if (i % 5 == 0) { "Buzz"; w = 1; }
	if (w == 0) i
	if (w == 1) "
"
}
quit

BCPL[edit]

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()
    $)
$)

beeswax[edit]

Also see on FizzBuzz/EsoLang

“Ordinary” FizzBuzz solution:

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


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):

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

Befunge[edit]

See FizzBuzz/EsoLang

blz[edit]

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

Boo[edit]

def fizzbuzz(size):
    for i in range(1, size):
        if i%15 == 0:
            print 'FizzBuzz'
        elif i%5 == 0:
            print 'Buzz'
        elif i%3 == 0:
            print 'Fizz'
        else:
            print i

fizzbuzz(101)

BQN[edit]

(∾´∾⟜"Fizz"‿"Buzz"/˜·(¬∨´)⊸∾0=3‿5|⊢)¨1+↕100

Using the Catch modifier for flow control

((∾´"fizz"‿"buzz"/˜0=3‿5|⊢)⎊⊢)¨1+↕100

Bracmat[edit]

0:?i&whl'(1+!i:<101:?i&out$(mod$(!i.3):0&(mod$(!i.5):0&FizzBuzz|Fizz)|mod$(!i.5):0&Buzz|!i))

Same code, pretty printed:

  0:?i
&   whl
  ' ( 1+!i:<101:?i
    &   out
      $ (   mod$(!i.3):0
          & ( mod$(!i.5):0&FizzBuzz
            | Fizz
            )
        | mod$(!i.5):0&Buzz
        | !i
        )
    )

Brainf***[edit]

See FizzBuzz/EsoLang

Brat[edit]

1.to 100 { n |
  true? n % 15 == 0
    { p "FizzBuzz" }
    { true? n % 3 == 0
      { p "Fizz" }
      { true? n % 5 == 0
        { p "Buzz" }
        { p n }
      }
    }
  }

BrightScript (for Roku)[edit]

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

C[edit]

For 2 prime numbers and based on a similar minimal JavaScript solution with low signal-to-noise, the C code is:

  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 );

With 4 prime numbers:

  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 );
Output: ..., 89, FizBuz, Goz, 92, Fiz, 94, Buz, Fiz, 97, Goz, FizKaz, Buz

One line version, with pretty printing

#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");
}
This actually works (the array init part, saves 6 bytes of static data, whee):
#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;
}
#include<stdio.h>

int main (void)
{
    int i;
    for (i = 1; i <= 100; i++)
    {
        if (!(i % 15))
            printf ("FizzBuzz");
        else if (!(i % 3))
            printf ("Fizz");
        else if (!(i % 5))
            printf ("Buzz");
        else
            printf ("%d", i);

        printf("\n");
    }
    return 0;
}

Implicit int main and return 0 (C99+):

#include <stdio.h>
 
main() {
  int i = 1;
  while(i <= 100) {
    if(i % 15 == 0)
      puts("FizzBuzz");
    else if(i % 3 == 0)
      puts("Fizz");
    else if(i % 5 == 0)
      puts("Buzz");
    else
      printf("%d\n", i);
    i++;
  }
}

obfuscated:

#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;}
With numbers theory:
#include <stdio.h>

int main(void)
{
    for (int i = 1; i <= 100; ++i) {
        if (i % 3 == 0) printf("fizz");
        if (i % 5 == 0) printf("buzz");
        if (i * i * i * i % 15 == 1) printf("%d", i);
        puts("");
    }
}

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

#include <stdio.h>
int main()
{
    for (int i=0;++i<101;puts(""))
    {
        char f[] = "FizzBuzz%d";
        f[8-i%5&12]=0;
        printf (f+(-i%3&4+f[8]/8), i);
    }
}

C#[edit]

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);
            }
        }
    }
}
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());
        }
    }
}
using System;
using System.Linq;

namespace FizzBuzz
{
    class Program
    {
        static void Main(string[] args)
        {
            Enumerable.Range(1, 100)
                .Select(a => String.Format("{0}{1}", a % 3 == 0 ? "Fizz" : string.Empty, a % 5 == 0 ? "Buzz" : string.Empty))
                .Select((b, i) => String.IsNullOrEmpty(b) ? (i + 1).ToString() : b)
                .ToList()
                .ForEach(Console.WriteLine);
        }
    }
}
using System;
using System.Globalization;
using System.Linq;

namespace FizzBuzz
{
    class Program
    {
        static void Main()
        {
            Enumerable.Range(1, 100)
                .GroupBy(e => e % 15 == 0 ? "FizzBuzz" : e % 5 == 0 ? "Buzz" : e % 3 == 0 ? "Fizz" : string.Empty)
                .SelectMany(item => item.Select(x => new { 
                    Value = x, 
                    Display = String.IsNullOrEmpty(item.Key) ? x.ToString(CultureInfo.InvariantCulture) : item.Key 
                }))
                .OrderBy(x => x.Value)
                .Select(x => x.Display)
                .ToList()
                .ForEach(Console.WriteLine);
        }
    }
}
using System;
namespace FizzBuzz
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 100; i++)
            {
                if (i % 15 == 0)
                {
                    Console.WriteLine("FizzBuzz");
                }
                else if (i % 3 == 0)
                {
                    Console.WriteLine("Fizz");
                }
                else if (i % 5 == 0)
                {
                    Console.WriteLine("Buzz");
                }
                else
                {
                    Console.WriteLine(i);
                }
            }
        }
    }
}
using System;
using System.Globalization;

namespace Rosettacode
{
    class Program
    {
        static void Main()
        {
            for (var number = 0; number < 100; number++)
            {
                if ((number % 3) == 0 & (number % 5) == 0)
                {
                    //For numbers which are multiples of both three and five print "FizzBuzz".
                    Console.WriteLine("FizzBuzz");
                    continue;
                }

                if ((number % 3) == 0) Console.WriteLine("Fizz");
                if ((number % 5) == 0) Console.WriteLine("Buzz");
                if ((number % 3) != 0 && (number % 5) != 0) Console.WriteLine(number.ToString(CultureInfo.InvariantCulture));

                if (number % 5 == 0)
                {
                    Console.WriteLine(Environment.NewLine);
                }
            }
        }
    }
}
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())));
        }
    }
}

With C#8 switch expressions[edit]

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));
        }
    }
}

TDD using delegates[edit]

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FizzBuzz
{
    [TestClass]
    public class FizzBuzzTest
    {
        private FizzBuzz fizzBuzzer;

        [TestInitialize]
        public void Initialize()
        {
            fizzBuzzer = new FizzBuzz();
        }

        [TestMethod]
        public void Give4WillReturn4()
        {
            Assert.AreEqual("4", fizzBuzzer.FizzBuzzer(4));
        }

        [TestMethod]
        public void Give9WillReturnFizz()
        {
            Assert.AreEqual("Fizz", fizzBuzzer.FizzBuzzer(9));
        }

        [TestMethod]
        public void Give25WillReturnBuzz()
        {
            Assert.AreEqual("Buzz", fizzBuzzer.FizzBuzzer(25));
        }

        [TestMethod]
        public void Give30WillReturnFizzBuzz()
        {
            Assert.AreEqual("FizzBuzz", fizzBuzzer.FizzBuzzer(30));
        }

        [TestMethod]
        public void First15()
        {
            ICollection expected = new ArrayList
                {"1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"};

            var actual = Enumerable.Range(1, 15).Select(x => fizzBuzzer.FizzBuzzer(x)).ToList();

            CollectionAssert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void From1To100_ToShowHowToGet100()
        {
            const int expected = 100;
            var actual = Enumerable.Range(1, 100).Select(x => fizzBuzzer.FizzBuzzer(x)).ToList();

            Assert.AreEqual(expected, actual.Count);
        }
    }

    public class FizzBuzz
    {
        private delegate string Xzzer(int value);
        private readonly IList<Xzzer> _functions = new List<Xzzer>();

        public FizzBuzz()
        {
            _functions.Add(x => x % 3 == 0 ? "Fizz" : "");
            _functions.Add(x => x % 5 == 0 ? "Buzz" : "");
        }

        public string FizzBuzzer(int value)
        {
            var result = _functions.Aggregate(String.Empty, (current, function) => current + function.Invoke(value));
            return String.IsNullOrEmpty(result) ? value.ToString(CultureInfo.InvariantCulture) : result;
        }
    }
}

Good old C ways[edit]

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

C++[edit]

minimal conditions[edit]

#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;
}

with modulo[edit]

#include <iostream>

using namespace std;
int main ()
{
       for (int i = 1; i <= 100; i++) 
       {
               if ((i % 15) == 0)
                       cout << "FizzBuzz\n";
               else if ((i % 3) == 0)
                       cout << "Fizz\n";
               else if ((i % 5) == 0)
                       cout << "Buzz\n";
               else
                       cout << i << "\n";
       }
       return 0;
}

without modulo 15[edit]

#include <iostream>
using namespace std;

int main()
{
  for (int i = 0; i <= 100; ++i)
  {
    bool fizz = (i % 3) == 0;
    bool buzz = (i % 5) == 0;
    if (fizz)
      cout << "Fizz";
    if (buzz)
      cout << "Buzz";
    if (!fizz && !buzz)
      cout << i;
    cout << "\n";
  }
  return 0;
}

without modulo[edit]

Modulo can be expensive on some architectures.

#include <iostream>

int main()
{
    int i, f = 2, b = 4; 

    for ( i = 1 ; i <= 100 ; ++i, --f, --b )
    {
        if ( f && b ) { std::cout << i;             }
        if ( !f )     { std::cout << "Fizz"; f = 3; }
        if ( !b )     { std::cout << "Buzz"; b = 5; }
        std::cout << std::endl;
    }

    return 0;
}

using std::transform[edit]

Works with: C++11
#include <iostream>                                                                                                     
#include <algorithm>
#include <vector>

int main()
{
  std::vector<int> range(100);
  std::iota(range.begin(), range.end(), 1);

  std::vector<std::string> values;
  values.resize(range.size());

  auto fizzbuzz = [](int i) -> std::string {
    if ((i%15) == 0) return "FizzBuzz";
    if ((i%5) == 0)  return "Buzz";
    if ((i%3) == 0)  return "Fizz";
    return std::to_string(i);
  };

  std::transform(range.begin(), range.end(), values.begin(), fizzbuzz);

  for (auto& str: values) std::cout << str << std::endl;

  return 0;
}

metaprogramming[edit]

Version computing FizzBuzz at compile time with metaprogramming:

#include <iostream>

template <int n, int m3, int m5> 
struct fizzbuzz : fizzbuzz<n-1, (n-1)%3, (n-1)%5>
{
  fizzbuzz() 
  { std::cout << n << std::endl; }
};

template <int n>
struct fizzbuzz<n, 0, 0> : fizzbuzz<n-1, (n-1)%3, (n-1)%5>
{
  fizzbuzz() 
  { std::cout << "FizzBuzz" << std::endl; }
};

template <int n, int p>
struct fizzbuzz<n, 0, p> : fizzbuzz<n-1, (n-1)%3, (n-1)%5>
{
  fizzbuzz() 
  { std::cout << "Fizz" << std::endl; }
};

template <int n, int p>
struct fizzbuzz<n, p, 0> : fizzbuzz<n-1, (n-1)%3, (n-1)%5>
{
  fizzbuzz() 
  { std::cout << "Buzz" << std::endl; }
};

template <>
struct fizzbuzz<0,0,0>
{
  fizzbuzz() 
  { std::cout << 0 << std::endl; }
};

template <int n>
struct fb_run
{
  fizzbuzz<n, n%3, n%5> fb;
};

int main()
{
  fb_run<100> fb;
  return 0;
}

hardcore templates[edit]

Compile with -ftemplate-depth-9000 -std=c++0x:

#include <iostream>
#include <string>
#include <cstdlib>
#include <boost/mpl/string.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/size_t.hpp>

using namespace std;
using namespace boost;

///////////////////////////////////////////////////////////////////////////////
// exponentiation calculations
template <int accum, int base, int exp> struct POWER_CORE : POWER_CORE<accum * base, base, exp - 1>{};

template <int accum, int base>
struct POWER_CORE<accum, base, 0>
{
    enum : int { val = accum };
};

template <int base, int exp> struct POWER : POWER_CORE<1, base, exp>{};

///////////////////////////////////////////////////////////////////////////////
// # of digit calculations
template <int depth, unsigned int i> struct NUM_DIGITS_CORE : NUM_DIGITS_CORE<depth + 1, i / 10>{};

template <int depth>
struct NUM_DIGITS_CORE<depth, 0>
{
    enum : int { val = depth};
};

template <int i> struct NUM_DIGITS : NUM_DIGITS_CORE<0, i>{};

template <>
struct NUM_DIGITS<0>
{
    enum : int { val = 1 };
};

///////////////////////////////////////////////////////////////////////////////
// Convert digit to character (1 -> '1')
template <int i>
struct DIGIT_TO_CHAR
{
    enum : char{ val = i + 48 };
};

///////////////////////////////////////////////////////////////////////////////
// Find the digit at a given offset into a number of the form 0000000017
template <unsigned int i, int place> // place -> [0 .. 10]
struct DIGIT_AT
{
    enum : char{ val = (i / POWER<10, place>::val) % 10 };
};

struct NULL_CHAR
{
    enum : char{ val = '\0' };
};

///////////////////////////////////////////////////////////////////////////////
// Convert the digit at a given offset into a number of the form '0000000017' to a character
template <unsigned int i, int place> // place -> [0 .. 9]
    struct ALT_CHAR : DIGIT_TO_CHAR< DIGIT_AT<i, place>::val >{};

///////////////////////////////////////////////////////////////////////////////
// Convert the digit at a given offset into a number of the form '17' to a character

// Template description, with specialization to generate null characters for out of range offsets
template <unsigned int i, int offset, int numDigits, bool inRange>  
    struct OFFSET_CHAR_CORE_CHECKED{};
template <unsigned int i, int offset, int numDigits>                
    struct OFFSET_CHAR_CORE_CHECKED<i, offset, numDigits, false> : NULL_CHAR{};
template <unsigned int i, int offset, int numDigits>                
    struct OFFSET_CHAR_CORE_CHECKED<i, offset, numDigits, true>  : ALT_CHAR<i, (numDigits - offset) - 1 >{};

// Perform the range check and pass it on
template <unsigned int i, int offset, int numDigits>
    struct OFFSET_CHAR_CORE : OFFSET_CHAR_CORE_CHECKED<i, offset, numDigits, offset < numDigits>{};

// Calc the number of digits and pass it on
template <unsigned int i, int offset>
    struct OFFSET_CHAR : OFFSET_CHAR_CORE<i, offset, NUM_DIGITS<i>::val>{};

///////////////////////////////////////////////////////////////////////////////
// Integer to char* template. Works on unsigned ints.
template <unsigned int i>
struct IntToStr
{
    const static char str[];
    typedef typename mpl::string<
    OFFSET_CHAR<i, 0>::val,
    OFFSET_CHAR<i, 1>::val,
    OFFSET_CHAR<i, 2>::val,
    OFFSET_CHAR<i, 3>::val,
    OFFSET_CHAR<i, 4>::val,
    OFFSET_CHAR<i, 5>::val,
    /*OFFSET_CHAR<i, 6>::val,
    OFFSET_CHAR<i, 7>::val,
    OFFSET_CHAR<i, 8>::val,
    OFFSET_CHAR<i, 9>::val,*/
    NULL_CHAR::val>::type type;
};

template <unsigned int i>
const char IntToStr<i>::str[] = 
{
    OFFSET_CHAR<i, 0>::val,
    OFFSET_CHAR<i, 1>::val,
    OFFSET_CHAR<i, 2>::val,
    OFFSET_CHAR<i, 3>::val,
    OFFSET_CHAR<i, 4>::val,
    OFFSET_CHAR<i, 5>::val,
    OFFSET_CHAR<i, 6>::val,
    OFFSET_CHAR<i, 7>::val,
    OFFSET_CHAR<i, 8>::val,
    OFFSET_CHAR<i, 9>::val,
    NULL_CHAR::val
};

template <bool condition, class Then, class Else>
struct IF
{
    typedef Then RET;
};

template <class Then, class Else>
struct IF<false, Then, Else>
{
    typedef Else RET;
};


template < typename Str1, typename Str2 >
struct concat : mpl::insert_range<Str1, typename mpl::end<Str1>::type, Str2> {};
template <typename Str1, typename Str2, typename Str3 >
struct concat3 : mpl::insert_range<Str1, typename mpl::end<Str1>::type, typename concat<Str2, Str3 >::type > {};

typedef typename mpl::string<'f','i','z','z'>::type fizz;
typedef typename mpl::string<'b','u','z','z'>::type buzz;
typedef typename mpl::string<'\r', '\n'>::type mpendl;
typedef typename concat<fizz, buzz>::type fizzbuzz;

// discovered boost mpl limitation on some length

template <int N>
struct FizzBuzz
{
    typedef typename concat3<typename FizzBuzz<N - 1>::type, typename IF<N % 15 == 0, typename fizzbuzz::type, typename IF<N % 3 == 0, typename fizz::type, typename IF<N % 5 == 0, typename buzz::type, typename IntToStr<N>::type >::RET >::RET >::RET, typename mpendl::type>::type type;
};

template <>
struct FizzBuzz<1>
{
    typedef mpl::string<'1','\r','\n'>::type type;
};

int main(int argc, char** argv)
{
    const int n = 7;
    std::cout << mpl::c_str<FizzBuzz<n>::type>::value << std::endl;
	return 0;
}

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).

Casio BASIC[edit]

See FizzBuzz/Basic

Cduce[edit]

(* FizzBuzz in CDuce *)

let format (n : Int) : Latin1 =
    if (n mod 3 = 0) || (n mod 5 = 0) then "FizzBuzz"
    else if (n mod 5 = 0) then "Buzz"
    else if (n mod 3 = 0) then "Fizz"
    else string_of (n);;

let fizz (n : Int, size : Int) : _ = 
    print (format (n) @ "\n");
    if (n = size) then
        n = 0 (* do nothing *)
    else
        fizz(n + 1, size);;

let fizbuzz (size : Int) : _ = fizz (1, size);;

let _ = fizbuzz(100);;

Ceylon[edit]

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);

Chapel[edit]

proc fizzbuzz(n) {
	for i in 1..n do
		if i % 15 == 0 then
			writeln("FizzBuzz");
		else if i % 5 == 0 then
			writeln("Buzz");
		else if i % 3 == 0 then
			writeln("Fizz");
		else
			writeln(i);
}

fizzbuzz(100);

Chef[edit]

See FizzBuzz/EsoLang

Clay[edit]

main() {
    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 print(i);
    }
}

Clipper[edit]

Also compiles with Harbour (Harbour 3.2.0dev (r1405201749))

PROCEDURE Main()

   LOCAL n
   LOCAL cFB 

   FOR n := 1 TO 100
      cFB := ""
      AEval( { { 3, "Fizz" }, { 5, "Buzz" } }, {|x| cFB += iif( ( n % x[ 1 ] ) == 0, x[ 2 ], "" ) } )
      ?? iif( cFB == "", LTrim( Str( n ) ), cFB ) + iif( n == 100, ".", ", " )
   NEXT

   RETURN

The advantage of this approach is that it is trivial to add another factor:

AEval( {{3,"Fizz"},{5,"Buzz"},{9,"Jazz"}}, {|x| cFB += Iif((n % x[1])==0, x[2], "")})

CLIPS[edit]

(deffacts count
  (count-to 100)
)

(defrule print-numbers
  (count-to ?max)
  =>
  (loop-for-count (?num ?max) do
    (if
      (= (mod ?num 3) 0)
      then
      (printout t "Fizz")
    )
    (if
      (= (mod ?num 5) 0)
      then
      (printout t "Buzz")
    )
    (if
      (and (> (mod ?num 3) 0) (> (mod ?num 5) 0))
      then
      (printout t ?num)
    )
    (priint depth, unsigned int i> struct NUM_DIGITS_CORE : NUM_DIGITS_COREntout t crlf)
  )
)

Clojure[edit]

(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))
(defn fizzbuzz [start finish] 
  (map (fn [n]
	(cond
		(zero? (mod n 15)) "FizzBuzz"
		(zero? (mod n 3)) "Fizz"
		(zero? (mod n 5)) "Buzz"
		:else n))
	(range start finish)))
(fizzbuzz 1 100)
(map (fn [x] (cond (zero? (mod x 15)) "FizzBuzz" 
                   (zero? (mod x 5)) "Buzz"
                   (zero? (mod x 3)) "Fizz"
		     :else x))
     (range 1 101))
(map #(let [s (str (if (zero? (mod % 3)) "Fizz") (if (zero? (mod % 5)) "Buzz"))] (if (empty? s) % s)) (range 1 101))
(def fizzbuzz (map 
  #(cond (zero? (mod % 15)) "FizzBuzz"
         (zero? (mod % 5)) "Buzz"
         (zero? (mod % 3)) "Fizz"
               :else %)
  (iterate inc 1)))
(defn fizz-buzz 
  ([] (fizz-buzz (range 1 101)))
  ([lst]
     (letfn [(fizz? [n] (zero? (mod n 3)))
	     (buzz? [n] (zero? (mod n 5)))]
       (let [f     "Fizz" 
	     b     "Buzz" 
	     items (map (fn [n]
			  (cond (and (fizz? n) (buzz? n)) (str f b)
				(fizz? n) f
				(buzz? n) b
				:else n))
			lst)] items))))
(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))
(take 100 (map #(let [s (str %2 %3) ] (if (seq s) s (inc %)) )
            (range)
            (cycle [ "" "" "Fizz" ])
            (cycle [ "" "" "" "" "Buzz" ])))
(map #(nth (conj (cycle [% % "Fizz" % "Buzz" "Fizz" % % "Fizz" "Buzz" % "Fizz" % % "FizzBuzz"]) %) %) (range 1 101))
(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)))
(take 100
      (map #(if (pos? (compare %1 %2)) %1 %2)
           (map str (drop 1 (range)))
           (map str (cycle ["" "" "Fizz"]) (cycle ["" "" "" "" "Buzz"]))))
;;Using clojure maps
(defn fizzbuzz
  [n]
  (let [rule {3 "Fizz"
              5 "Buzz"}
        divs (->> rule
                  (map first)
                  sort
                  (filter (comp (partial = 0)
                                (partial rem n))))]
    (if (empty? divs)
      (str n)
      (->> divs
           (map rule)
           (apply str)))))

(defn allfizzbuzz
  [max]
  (map fizzbuzz (range 1 (inc max))))
(take 100
   (map #(str %1 %2 (if-not (or %1 %2) %3))
        (cycle [nil nil "Fizz"])
        (cycle [nil nil nil nil "Buzz"])
        (rest (range))
   ))
(take 100
  (
    (fn [& fbspec]
      (let [
             fbseq #(->> (repeat nil) (cons %2) (take %1) reverse cycle)
             strfn #(apply str (if (every? nil? (rest %&)) (first %&)) (rest %&))
          ]
        (->>
          fbspec
          (partition 2)
          (map #(apply fbseq %))
          (apply map strfn (rest (range)))
          ) ;;endthread
      ) ;;endlet
    ) ;;endfn
    3 "Fizz" 5 "Buzz" 7 "Bazz"
  ) ;;endfn apply
) ;;endtake
(take 100
      (map-indexed
        #(case %2 14 "FizzBuzz" (2 5 8 11) "Fizz" (4 9) "Buzz" (inc %1))
        (cycle (range 15))
        )
)
(take 100
       (->>
          (map str (cycle [nil nil "Fizz"]) (cycle [nil nil nil nil "Buzz"]))
          (map-indexed #(if (empty? %2) (inc %1) %2))
       )
)
(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"])
      )
)

CLU[edit]

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

CMake[edit]

foreach(i RANGE 1 100)
  math(EXPR off3 "${i} % 3")
  math(EXPR off5 "${i} % 5")
  if(NOT off3 AND NOT off5)
    message(FizzBuzz)
  elseif(NOT off3)
    message(Fizz)
  elseif(NOT off5)
    message(Buzz)
  else()
    message(${i})
  endif()
endforeach(i)

COBOL[edit]

Canonical version[edit]

Works with: OpenCOBOL
      * FIZZBUZZ.COB
      * cobc -x -g FIZZBUZZ.COB
      *
       IDENTIFICATION        DIVISION.
       PROGRAM-ID.           fizzbuzz.
       DATA                  DIVISION.
       WORKING-STORAGE       SECTION.
       01 CNT      PIC 9(03) VALUE 1.
       01 REM      PIC 9(03) VALUE 0.
       01 QUOTIENT PIC 9(03) VALUE 0.
       PROCEDURE             DIVISION.
      *
       PERFORM UNTIL CNT > 100
         DIVIDE 15 INTO CNT GIVING QUOTIENT REMAINDER REM
         IF REM = 0
           THEN
             DISPLAY "FizzBuzz " WITH NO ADVANCING
           ELSE
             DIVIDE 3 INTO CNT GIVING QUOTIENT REMAINDER REM
             IF REM = 0
               THEN
                 DISPLAY "Fizz " WITH NO ADVANCING
               ELSE
                 DIVIDE 5 INTO CNT GIVING QUOTIENT REMAINDER REM
                 IF REM = 0
                   THEN
                     DISPLAY "Buzz " WITH NO ADVANCING
                   ELSE
                     DISPLAY CNT " " WITH NO ADVANCING
                 END-IF
             END-IF
         END-IF
         ADD 1 TO CNT
       END-PERFORM
       DISPLAY ""
       STOP RUN.

Simpler version[edit]

I know this doesn't have the full-bodied, piquant flavor expected from COBOL, but it is a little shorter.

Works with: OpenCOBOL
Identification division.
Program-id. fizz-buzz.

Data division.
Working-storage section.

01 num pic 999.

Procedure division.
    Perform varying num from 1 by 1 until num > 100
        if function mod (num, 15) = 0 then display "fizzbuzz"
        else if function mod (num, 3) = 0 then display "fizz"
        else if function mod (num, 5) = 0 then display "buzz"
        else display num
    end-perform.
    Stop run.

Evaluate Version[edit]

I think this shows clearly that it's resolving the problem and illuminating the rules specified

Works with: OpenCOBOL
       IDENTIFICATION DIVISION.
       PROGRAM-ID.  FIZZBUZZ.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  X PIC 999.
       01  Y PIC 999.
       01  REM3 PIC 999.
       01  REM5 PIC 999.
       PROCEDURE DIVISION.
           PERFORM VARYING X FROM 1 BY 1 UNTIL X > 100
               DIVIDE X BY 3 GIVING Y REMAINDER REM3
               DIVIDE X BY 5 GIVING Y REMAINDER REM5
            EVALUATE REM3 ALSO REM5
              WHEN ZERO ALSO ZERO
                DISPLAY "FizzBuzz"
              WHEN ZERO ALSO ANY
                DISPLAY "Fizz"
              WHEN ANY ALSO ZERO
                DISPLAY "Buzz"
              WHEN OTHER
                DISPLAY X
            END-EVALUATE
           END-PERFORM
           STOP RUN
           .

Chase the Fizz[edit]

Works with: OpenCOBOL

A solution that simply evaluates and adds.

         >>SOURCE FORMAT FREE
identification division.
program-id. fizzbuzz.
data division.
working-storage section.
01  i pic 999.
01  fizz pic 999 value 3.
01  buzz pic 999 value 5.
procedure division.
start-fizzbuzz.
    perform varying i from 1 by 1 until i > 100 
        evaluate i also i
        when fizz also buzz
            display 'fizzbuzz'
            add 3 to fizz
            add 5 to buzz
        when fizz also any
            display 'fizz'
            add 3 to fizz
        when buzz also any
            display 'buzz'
            add 5 to buzz
        when other
            display i
        end-evaluate
    end-perform
    stop run
    .
end program fizzbuzz.

Coco[edit]

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
for i from 1 to 100
    console.log(['Fizz' unless i % 3] + ['Buzz' unless i % 5] or String(i))

Coconut[edit]

def fizzbuzz(n):
      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

CoffeeScript[edit]

for i in [1..100]
  if i % 15 is 0
    console.log "FizzBuzz"
  else if i % 3 is 0
    console.log "Fizz"
  else if i % 5 is 0
    console.log "Buzz"
  else
    console.log i
for i in [1..100]
  console.log \
    if i % 15 is 0
      "FizzBuzz"
    else if i % 3 is 0
      "Fizz"
    else if i % 5 is 0
      "Buzz"
    else
      i
for i in [1..100]
  console.log(['Fizz' if i % 3 is 0] + ['Buzz' if i % 5 is 0] or i)

ColdFusion[edit]

<Cfloop from="1" to="100" index="i">
  <Cfif i mod 15 eq 0>FizzBuzz
  <Cfelseif i mod 5 eq 0>Fizz
  <Cfelseif i mod 3 eq 0>Buzz
  <Cfelse><Cfoutput>#i# </Cfoutput>
  </Cfif>      
</Cfloop>

cfscript version

<cfscript>
result = "";
  for(i=1;i<=100;i++){
    result=ListAppend(result, (i%15==0) ? "FizzBuzz": (i%5==0) ? "Buzz" : (i%3 eq 0)? "Fizz" : i );
  }
  WriteOutput(result);
</cfscript>

Comal[edit]

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

Comefrom0x10[edit]

fizzbuzz
  mod_three = 3
  mod_five = 5
  comefrom fizzbuzz
  n
  comefrom fizzbuzz if n is mod_three
  comefrom fizzbuzz if n is mod_five
  n = n + 1

  fizz
    comefrom fizzbuzz if n is mod_three
    'Fizz'...
    mod_three = mod_three + 3
    linebreak
      # would like to write "unless mod_three is mod_five"
      comefrom fizz if mod_three - mod_five - 3
      ''

  buzz
    comefrom fizzbuzz if n is mod_five
    'Buzz'
    mod_five = mod_five + 5

  comefrom fizzbuzz if n is 100

Commodore BASIC[edit]

See FizzBuzz/Basic

Common Lisp[edit]

Solution 1:

(defun fizzbuzz ()
  (loop for x from 1 to 100 do
    (princ (cond ((zerop (mod x 15)) "FizzBuzz")
                 ((zerop (mod x 3))  "Fizz")
                 ((zerop (mod x 5))  "Buzz")
                 (t                  x)))
    (terpri)))

Solution 2:

(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)))))

Solution 3:

(defun fizzbuzz ()
  (loop for n from 1 to 100
     do (format t "~&~[~[FizzBuzz~:;Fizz~]~*~:;~[Buzz~*~:;~D~]~]~%"
                (mod n 3) (mod n 5) n)))

Solution 4:

(loop as n from 1 to 100
      as fizz = (zerop (mod n 3))
      as buzz = (zerop (mod n 5))
      as numb = (not (or fizz buzz))
      do
  (format t
   "~&~:[~;Fizz~]~:[~;Buzz~]~:[~;~D~]~%"
   fizz buzz numb n))

Solution 5:

(format t "~{~:[~&~;~:*~:(~a~)~]~}"
  (loop as n from 1 to 100
        as f = (zerop (mod n 3))
        as b = (zerop (mod n 5))
        collect nil
        if f collect 'fizz
        if b collect 'buzz
        if (not (or f b)) collect n))

Solution 6:

(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)))

Solution 7:

(defun core (x)
  (mapcar 
    #'(lambda (a b) (if (equal 0 (mod x a)) b x)) 
    '(3 5) 
    '("fizz" "buzz")))

(defun filter-core (x)
  (if (equal 1 (length (remove-duplicates x)))
    (list (car x))
    (remove-if-not #'stringp x)))

(defun fizzbuzz (x)
  (loop for a from 1 to x do
    (print (format nil "~{~a~}" (filter-core (core a))))))

(fizzbuzz 100)

First 16 lines of output:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16

Alternate solution[edit]

I use Allegro CL 10.1

;; 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)

Output:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz

Coq[edit]

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.

Cowgol[edit]

Straightforward version[edit]

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;

No division[edit]

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 % be avoided, but also print_i8 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.)

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;

Craft Basic[edit]

See FizzBuzz/Basic

Crystal[edit]

1.upto(100) do |v|
  p fizz_buzz(v)
end

def fizz_buzz(value)
  word = ""
  word += "fizz" if value % 3 == 0
  word += "buzz" if value % 5 == 0
  word += value.to_s if word.empty?
  word
end

A more natural solution with the string building:

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

CSS[edit]

<!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>

Cubescript[edit]

alias fizzbuzz [
	loop i 100 [
		push i (+ $i 1) [
			cond (! (mod $i 15)) [
				echo FizzBuzz
			] (! (mod $i 3)) [
				echo Fizz
			] (! (mod $i 5)) [
				echo Buzz
			] [
				echo $i
			]
		]
	]
]

D[edit]

import std.stdio, std.algorithm, std.conv;

/// With if-else.
void fizzBuzz(in uint n) {
    foreach (immutable i; 1 .. n + 1)
        if (!(i % 15))
            "FizzBuzz".writeln;
        else if (!(i % 3))
            "Fizz".writeln;
        else if (!(i % 5))
            "Buzz".writeln;
        else
            i.writeln;
}

/// With switch case.
void fizzBuzzSwitch(in uint n) {
    foreach (immutable i; 1 .. n + 1)
        switch (i % 15) {
            case 0:
                "FizzBuzz".writeln;
                break;
            case 3, 6, 9, 12:
                "Fizz".writeln;
                break;
            case 5, 10:
                "Buzz".writeln;
                break;
            default:
                i.writeln;
        }
}

void fizzBuzzSwitch2(in uint n) {
    foreach (immutable i; 1 .. n + 1)
        (i % 15).predSwitch(
        0,       "FizzBuzz",
        3,       "Fizz",
        5,       "Buzz",
        6,       "Fizz",
        9,       "Fizz",
        10,      "Buzz",
        12,      "Fizz",
        /*else*/ i.text).writeln;
}

void main() {
    100.fizzBuzz;
    writeln;
    100.fizzBuzzSwitch;
    writeln;
    100.fizzBuzzSwitch2;
}

Alternate version calculating values at compile time:

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;
}

Dart[edit]

main() {
  for (int i = 1; i <= 100; i++) {
    List<String> out = [];
    if (i % 3 == 0)
      out.add("Fizz");
    if (i % 5 == 0)
      out.add("Buzz");
    print(out.length > 0 ? out.join("") : i);
  }
}

dc[edit]

Translation of: bc
[[Fizz]P 1 sw]sF
[[Buzz]P 1 sw]sB
[li p sz]sN
[[
]P]sW
[
 0 sw         [w = 0]sz
 li 3 % 0 =F  [Fizz if 0 == i % 3]sz
 li 5 % 0 =B  [Buzz if 0 == i % 5]sz
 lw 0 =N      [print Number if 0 == w]sz
 lw 1 =W      [print neWline if 1 == w]sz
 li 1 + si    [i += 1]sz
 li 100 !<L   [continue Loop if 100 >= i]sz 
]sL
1 si          [i = 1]sz
0 0 =L        [enter Loop]sz

The bc translation written in dc style.

# dc is stack based, so we use the stack instead of a variable for our 
# current number.

1                       # Number = 1
[[Fizz]n 1 sw]sF        # Prints "Fizz" prevents Number from printing
[[Buzz]n 1 sw]sB        # Prints "Buzz" prevents Number from printing
[dn]sN                  # Prints Number
[
        dd              # Put two extra copies of Number on stack
        0 sw            # w = 0
        3% 0=F          # Fizz if 0 == Number % 3 (destroys 1st copy)
        5% 0=B          # Buzz if 0 == Number % 5 (destroys 2nd copy)
        lw 0=N          # Print Number if 0 == w
        [
]n                      # Print new line
        1+d             # Number += 1 and put extra copy on stack
        100!<L          # Continue Loop if 100 >= Number (destroys copy)
]dsLx                   # Enter Loop

Delphi[edit]

program FizzBuzz;

{$APPTYPE CONSOLE}

uses SysUtils;

var
  i: Integer;
begin
  for i := 1 to 100 do
  begin
    if i mod 15 = 0 then
      Writeln('FizzBuzz')
    else if i mod 3 = 0 then
      Writeln('Fizz')
    else if i mod 5 = 0 then
      Writeln('Buzz')
    else
      Writeln(i);
  end;
end.

DeviousYarn[edit]

each { x range(1 100)
    ?  { divisible(x 3)
        p:'Fizz' }
    ?  { divisible(x 5)
        p:'Buzz' }
    -? { !:divisible(x 3)
        p:x }
    o
}

Draco[edit]

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

DUP[edit]

FizzBuzz, realized using two different methods for string/character output:

Output to STDOUT via single character output.

[$$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}

Output to STDOUT, using stored strings and a separately defined string output operator:

[\[^^>][$;,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}

DWScript[edit]

var i : Integer;

for i := 1 to 100 do begin
   if i mod 15 = 0 then
      PrintLn('FizzBuzz')
   else if i mod 3 = 0 then
      PrintLn('Fizz')
   else if i mod 5 = 0 then
      PrintLn('Buzz')
   else PrintLn(i);
end;

Dyalect[edit]

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
}
Output:
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19

Déjà Vu[edit]

for i range 1 100:
	if = 0 % i 15:
		"FizzBuzz"
	elseif = 0 % i 3:
		"Fizz"
	elseif = 0 % i 5:
		"Buzz"
	else:
		i
	!print

E[edit]

for i in 1..100 {
   println(switch ([i % 3, i % 5]) {
     match [==0, ==0] { "FizzBuzz" }
     match [==0, _  ] { "Fizz" }
     match [_,   ==0] { "Buzz" }
     match _          { i }
   })
 }

EasyLang[edit]

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
  .
.

ECL[edit]

DataRec := RECORD
    STRING  s;
END;

DataRec MakeDataRec(UNSIGNED c) := TRANSFORM
    SELF.s := MAP
        (
            c % 15 = 0  =>  'FizzBuzz',
            c % 3 = 0   =>  'Fizz',
            c % 5 = 0   =>  'Buzz',
            (STRING)c
        );
END;

d := DATASET(100,MakeDataRec(COUNTER));

OUTPUT(d);

Ecstasy[edit]

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();
            });
        }
    }
}

Eero[edit]

#import <Foundation/Foundation.h>

int main()
  autoreleasepool

    for int i in 1 .. 100
      s := ''
      if i % 3 == 0
        s << 'Fizz'
      if i % 5 == 0
        s << 'Buzz'
      Log( '(%d) %@', i, s )

  return 0

Egel[edit]

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

Eiffel[edit]

class
	APPLICATION

create
	make

feature

	make
		do
			fizzbuzz
		end

	fizzbuzz
	        --Numbers up to 100, prints "Fizz" instead of multiples of 3, and "Buzz" for multiples of 5.
	        --For multiples of both 3 and 5 prints "FizzBuzz".
		do
			across
				1 |..| 100 as c
			loop
				if c.item \\ 15 = 0 then
					io.put_string ("FIZZBUZZ%N")
				elseif c.item \\ 3 = 0 then
					io.put_string ("FIZZ%N")
				elseif c.item \\ 5 = 0 then
					io.put_string ("BUZZ%N")
				else
					io.put_string (c.item.out + "%N")
				end
			end
		end

end

Ela[edit]

open list

prt x | x % 15 == 0 = "FizzBuzz"
      | x % 3 == 0  = "Fizz"
      | x % 5 == 0  = "Buzz"
      | else        = x

[1..100] |> map prt

Elixir[edit]

Standard approaches[edit]

used case

Enum.each 1..100, fn x ->
  IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do
    { true, true }   -> "FizzBuzz"
    { true, false }  -> "Fizz"
    { false, true }  -> "Buzz"
    { false, false } -> x
  end)
end

Alternate approach using pipes and cond:

#!/usr/bin/env elixir
1..100 |> Enum.map(fn i ->
  cond do
    rem(i,3*5) == 0 -> "FizzBuzz"
    rem(i,3) == 0   -> "Fizz"
    rem(i,5) == 0   -> "Buzz"
    true            -> i
  end
end) |> Enum.each(fn i -> IO.puts i end)

used Stream.cycle version:

defmodule RC do
  def fizzbuzz(limit \\ 100) do
    fizz = Stream.cycle(["", "", "Fizz"])
    buzz = Stream.cycle(["", "", "", "", "Buzz"])
    Stream.zip(fizz, buzz)
    |> Enum.take(limit)
    |> Enum.with_index
    |> Enum.each(fn {{f,b},i} ->
         IO.puts if f<>b=="", do: i+1, else: f<>b
       end)
  end
end

RC.fizzbuzz

Yet another approach:

defmodule FizzBuzz do
  def fizzbuzz(n) when rem(n, 15) == 0, do: "FizzBuzz"
  def fizzbuzz(n) when rem(n,  5) == 0, do: "Buzz"
  def fizzbuzz(n) when rem(n,  3) == 0, do: "Fizz"
  def fizzbuzz(n),                      do: n  
end

Enum.each(1..100, &IO.puts FizzBuzz.fizzbuzz &1)

used anonymous function

f = fn(n) when rem(n,15)==0 -> "FizzBuzz"
      (n) when rem(n,5)==0  -> "Fizz"
      (n) when rem(n,3)==0  -> "Buzz"
      (n)                   -> n
end

for n <- 1..100, do: IO.puts f.(n)

Enum.at version: Returns nil if index is out of bounds.

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)

A macro too far[edit]

The Stream.cycle version above, but as an overpowered FizzBuzz DSL.

defmodule BadFizz do
  # Hand-rolls a bunch of AST before injecting the resulting FizzBuzz code.
  defmacrop automate_fizz(fizzers, n) do
    # To begin, we need to process fizzers to produce the various components
    # we're using in the final assembly. As told by Mickens telling as Antonio
    # Banderas, first you must specify a mapping function:
    build_parts = (fn {fz, n} ->
      ast_ref = {fz |> String.downcase |> String.to_atom, [], __MODULE__}
      clist   = List.duplicate("", n - 1) ++ [fz]
      cycle   = quote do: unquote(ast_ref) = unquote(clist) |> Stream.cycle

      {ast_ref, cycle}
    end)

    # ...and then a reducing function:
    collate = (fn 
      ({ast_ref, cycle}, {ast_refs, cycles}) ->
        {[ast_ref | ast_refs], [cycle | cycles]}
    end)

    # ...and then, my love, when you are done your computation is ready to run
    # across thousands of fizzbuzz:
    {ast_refs, cycles} = fizzers
    |> Code.eval_quoted([], __ENV__) |> elem(0) # Gotta unwrap this mystery code~
    |> Enum.sort(fn ({_, ap}, {_, bp}) -> ap < bp end) # Sort so that Fizz, 3 < Buzz, 5
    |> Enum.map(build_parts) 
    |> Enum.reduce({[], []}, collate)

    # Setup the anonymous functions used by Enum.reduce to build our AST components.
    # This was previously handled by List.foldl, but ejected because reduce/2's
    # default behavior reduces repetition.
    #
    # ...I was tempted to move these into a macro themselves, and thought better of it.
    build_zip    = fn (varname, ast) -> 
      quote do: Stream.zip(unquote(varname), unquote(ast))
    end
    build_tuple  = fn (varname, ast) -> 
      {:{}, [], [varname, ast]} 
    end
    build_concat = fn (varname, ast) ->
        {:<>,
        [context: __MODULE__, import: Kernel], # Hygiene values may change; accurate to Elixir 1.1.1
        [varname, ast]}
    end

    # Toss cycles into a block by hand, then smash ast_refs into
    # a few different computations on the cycle block results.
    cycles = {:__block__, [], cycles}
    tuple  = ast_refs |> Enum.reduce(build_tuple)
    zip    = ast_refs |> Enum.reduce(build_zip)
    concat = ast_refs |> Enum.reduce(build_concat)

    # Finally-- Now that all our components are assembled, we can put
    # together the fizzbuzz stream pipeline. After quote ends, this
    # block is injected into the caller's context.
    quote do
      unquote(cycles)

      unquote(zip)
      |> Stream.with_index
      |> Enum.take(unquote(n))
      |> Enum.each(fn 
      {unquote(tuple), i} ->
        ccats = unquote(concat)
        IO.puts if ccats == "", do: i + 1, else: ccats
      end)
    end
  end

  @doc ~S"""
    A fizzing, and possibly buzzing function. Somehow, you feel like you've
    seen this before. An old friend, suddenly appearing in Kafkaesque nightmare...

    ...or worse, during a whiteboard interview.
  """
  def fizz(n \\ 100) when is_number(n) do
    # In reward for all that effort above, we now have the latest in
    # programmer productivity: 
    #
    # A DSL for building arbitrary fizzing, buzzing, bazzing, and more!
    [{"Fizz", 3}, 
     {"Buzz", 5}#,
     #{"Bar", 7},
     #{"Foo", 243}, # -> Always printed last (largest number)
     #{"Qux", 34}
    ] 
    |> automate_fizz(n)
  end
end

BadFizz.fizz(100) # => Prints to stdout

Elm[edit]

A bit too simple:

import Html exposing (text)
import List exposing (map)

main =
  [1..100] |> map getWordForNum |> text

getWordForNum num =
  if num % 15 == 0 then
    "FizzBuzz"
  else if num % 3 == 0 then
    "Fizz"
  else if num % 5 == 0 then
    "Buzz"
  else
    String.fromInt num

A bit too clever:

import Html exposing (text)
import List exposing (map)
import String exposing (join, fromInt)

main : Html.Html
main =
  [1..100] |> map fizzbuzz |> join " " |> text

fizzbuzz : Int -> String
fizzbuzz num =
  let
    fizz = if num % 3 == 0 then "Fizz" else ""
    buzz = if num % 5 == 0 then "Buzz" else ""
  in
    if fizz == buzz then
      fromInt num
    else
      fizz ++ buzz

Emacs Lisp[edit]

(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)))

Emojicode[edit]

Simple 1[edit]

🏁🍇
  🔂 i 🆕⏩ 1 101 1 ❗ 🍇
    ↪️ i 🚮 15 🙌 0 🍇
      😀 🔤FizzBuzz🔤 ❗
    🍉
    🙅↪️ i 🚮 3 🙌 0 🍇
      😀 🔤Fizz🔤 ❗
    🍉
    🙅↪️ i 🚮 5 🙌 0 🍇
      😀 🔤Buzz🔤 ❗
    🍉🙅🍇
      😀 🔤🧲i🧲🔤 ❗
    🍉
  🍉
🍉

Simple 2[edit]

🏁🍇
  🔂 i 🆕⏩ 1 101 1 ❗ 🍇
    🔤🔤 ➡️ 🖍🆕 msg
    ↪️ i 🚮 3 🙌 0 🍇
      🔤Fizz🔤 ➡️ 🖍 msg
    🍉
    ↪️ i 🚮 5 🙌 0 🍇
      🔤🧲msg🧲Buzz🔤 ➡️ 🖍 msg
    🍉
    ↪️ msg 🙌 🔤🔤 🍇
      😀 🔤🧲i🧲🔤 ❗
    🍉🙅🍇
      😀 🔤🧲msg🧲🔤 ❗
    🍉
  🍉
🍉

Enguage[edit]

FizzBuzz

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 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.

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.

On downloading this repo, if git and make are installed, this unit test can be run with:

    $ git clone https://github.com/martinwheatman/enguage.git
    $ cd enguage
    $ make jar
    $ export PATH=$PATH:./sbin
    $ java -jar lib/enguage.jar -T fizzbuzz

Output:

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 +++

Erlang[edit]

-spec fizzbuzz() -> Result :: string().
fizzbuzz() ->
    F = fun(N) when N rem 15 == 0 -> "FizzBuzz";
           (N) when N rem 3 == 0  -> "Fizz";
           (N) when N rem 5 == 0  -> "Buzz";
           (N) -> integer_to_list(N)
        end,
    lists:flatten([[F(N)] ++ ["\n"] || N <- lists:seq(1,100)]).

ERRE[edit]

PROGRAM FIZZ_BUZZ
!
! for rosettacode.org
!
BEGIN
 FOR A=1 TO 100 DO
   IF A MOD 15=0 THEN
      PRINT("FizzBuzz")
   ELSIF A MOD 3=0 THEN
      PRINT("Fizz")
   ELSIF A MOD 5=0 THEN
      PRINT("Buzz")
   ELSE
      PRINT(A)
   END IF
 END FOR
END PROGRAM

Euler[edit]

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 <- 0;
iLoop: if [ i <- i + 1 ] <= 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 $

Euphoria[edit]

Works with: Euphoria version 4.0.0

This is based on the VBScript example.

include std/utils.e

function fb( atom n )
	sequence fb
	if remainder( n, 15 ) = 0 then
		fb = "FizzBuzz"
	elsif remainder( n, 5 ) = 0 then
		fb = "Fizz"
	elsif remainder( n, 3 ) = 0 then
		fb = "Buzz"
	else
		fb = sprintf( "%d", n )
	end if
	return fb
end function
 
function fb2( atom n )
	return iif( remainder(n, 15) = 0, "FizzBuzz", 
		iif( remainder( n, 5 ) = 0, "Fizz", 
		iif( remainder( n, 3) = 0, "Buzz", sprintf( "%d", n ) ) ) ) 
end function

for i = 1 to 30 do
	printf( 1, "%s ", { fb( i ) } )
end for

puts( 1, "\n" )

for i = 1 to 30 do
	printf( 1, "%s ", { fb2( i ) } )
end for

puts( 1, "\n" )

F#[edit]

let fizzbuzz n =
    match n%3 = 0, n%5 = 0 with
    | true, false -> "fizz"
    | false, true -> "buzz"
    | true, true  -> "fizzbuzz"
    | _ -> string n

let printFizzbuzz() =
    [1..100] |> List.iter (fizzbuzz >> printfn "%s")
[1..100] 
|> List.map (fun x ->
            match x with 
            | _ when x % 15 = 0 ->"fizzbuzz"
            | _ when x % 5 = 0 -> "buzz"
            | _ when x % 3 = 0 -> "fizz"
            | _ ->  x.ToString())
|> List.iter (fun x -> printfn "%s" x)

Another example using (unnecessary) partial active pattern :D

let (|MultipleOf|_|) divisors number =
    if Seq.exists ((%) number >> (<>) 0) divisors
    then None
    else Some ()

let fizzbuzz = function
| MultipleOf [3; 5] -> "fizzbuzz"
| MultipleOf [3]    -> "fizz"
| MultipleOf [5]    -> "buzz"
| n                 -> string n

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

Factor[edit]

USING: math kernel io math.functions math.parser math.ranges ;
IN: fizzbuzz
: fizz ( n -- str ) 3 divisor? "Fizz" "" ? ;
: buzz ( n -- str ) 5 divisor? "Buzz" "" ? ;
: fizzbuzz ( n -- str ) dup [ fizz ] [ buzz ] bi append [ number>string ] [ nip ] if-empty ;
: main ( -- ) 100 [1,b] [ fizzbuzz print ] each ;
MAIN: main

More flexible variant without divisibility tests.

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

Falcon[edit]

for i in [1:101]
    switch i % 15
    case 0        : > "FizzBuzz"
    case 5,10     : > "Buzz"
    case 3,6,9,12 : > "Fizz"
    default       : > i
    end
end

FALSE[edit]

See FizzBuzz/EsoLang

Fantom[edit]

class FizzBuzz
{
  public static Void main ()
  {
    for (Int i:=1; i <= 100; ++i)
    {
      if (i % 15 == 0)
        echo ("FizzBuzz")
      else if (i % 3 == 0)
        echo ("Fizz")
      else if (i % 5 == 0) 
        echo ("Buzz") 
      else
        echo (i)
    }
  }
}

FBSL[edit]

No 'MOD 15' needed.

#APPTYPE CONSOLE

DIM numbers AS STRING
DIM imod5 AS INTEGER
DIM imod3 AS INTEGER

FOR DIM i = 1 TO 100
    numbers = ""
    imod3 = i MOD 3
    imod5 = i MOD 5
    IF NOT imod3 THEN numbers = "Fizz"
    IF NOT imod5 THEN numbers = numbers & "Buzz"
    IF imod3 AND imod5 THEN numbers = i
    PRINT numbers, " ";
NEXT

PAUSE
Output:
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fiz
z 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 Fi
zzBuzz 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
Press any key to continue...

Fe[edit]

There is no built-in mod function, but you can add it via the C API.

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))));
}

Then, you can solve 'FizzBuzz' the traditional way:

(= 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)))

Of course, you can solve this without mod:

(= 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)))

Fennel[edit]

(for [i 1 100]
  (print (if (= (% i 15) 0) :FizzBuzz
             (= (% i 3) 0) :Fizz
             (= (% i 5) 0) :Buzz
             i)))

Use pattern matching and recursive function:

(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)
Alternative matching pattern:
Translation of: D
(for [i 1 100]
  (print (match (% i 15)
           0                     :FizzBuzz
           (where (or 3 6 9 12)) :Fizz
           (where (or 5 10)      :Buzz
           _                      i)))

FOCAL[edit]

FITR is a built-in function that truncates a floating-point number to an integer. Note that FOCAL uses an arithmetic (three-way) IF statement, rather like early Fortran.

01.10 FOR I=1,100; DO 2.0
01.20 QUIT

02.10 SET ZB=I/15 - FITR(I/15)
02.20 IF (ZB) 2.4, 2.3, 2.4
02.30 TYPE "FizzBuzz" !
02.35 RETURN
02.40 SET Z=I/3 - FITR(I/3)
02.50 IF (Z) 2.7, 2.6, 2.7
02.60 TYPE "Fizz" !
02.65 RETURN
02.70 SET B=I/5 - FITR(I/5)
02.80 IF (B) 2.99, 2.9, 2.99
02.90 TYPE "Buzz" !
02.95 RETURN
02.99 TYPE %3, I, !

Fermat[edit]

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
Output:

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

Fish[edit]

See FizzBuzz/EsoLang#Fish

Forth[edit]

table-driven[edit]

: fizz ( n -- ) drop ." Fizz" ;
: buzz ( n -- ) drop ." Buzz" ;
: fb   ( n -- ) drop ." FizzBuzz" ;
: vector create does> ( n -- )
  over 15 mod cells + @ execute ;
vector .fizzbuzz
  ' fb   , ' . ,    ' . ,
  ' fizz , ' . ,    ' buzz ,
  ' fizz , ' . ,    ' . ,
  ' fizz , ' buzz , ' . ,
  ' fizz , ' . ,    ' . ,

or the classic approach[edit]

: .fizzbuzz ( n -- )
  0 pad c!
  dup 3 mod 0= if s" Fizz" pad  place then
  dup 5 mod 0= if s" Buzz" pad +place then
  pad c@ if drop pad count type else . then ;

: zz ( n -- )
  1+ 1 do i .fizzbuzz cr loop ;
100 zz

the well factored approach[edit]

SYNONYM is a Forth200x word.

SYNONYM NOT INVERT \ Bitwise boolean not

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

FizzBuzz

the unrolled approach[edit]

: n     ( n -- n+1 )    dup .         1+ ;
: f     ( n -- n+1 )    ." Fizz "     1+ ;
: b     ( n -- n+1 )    ." Buzz "     1+ ;
: fb    ( n -- n+1 )    ." FizzBuzz " 1+ ;
: fb10  ( n -- n+10 )   n n f n b f n n f b ;
: 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 ;

Fortran[edit]

In ANSI FORTRAN 77 or later use structured IF-THEN-ELSE (example uses some ISO Fortran 90 features):

program fizzbuzz_if
   integer :: i
   
   do i = 1, 100
      if     (mod(i,15) == 0) then; print *, 'FizzBuzz'
      else if (mod(i,3) == 0) then; print *, 'Fizz'
      else if (mod(i,5) == 0) then; print *, 'Buzz'
      else;                         print *, i
      end if
   end do
end program fizzbuzz_if

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.

program FizzBuzz
implicit none
integer :: i = 1

do i = 1, 100
    if (Mod(i,3) == 0)write(*,"(A)",advance='no')  "Fizz"
    if (Mod(i,5) == 0)write(*,"(A)",advance='no') "Buzz"
    if (Mod(i,3) /= 0 .and. Mod(i,5) /=0 )write(*,"(I3)",advance='no') i
    print *, ""
end do
end program FizzBuzz

In ISO Fortran 90 or later use SELECT-CASE statement:

program fizzbuzz_select
    integer :: i
    
    do i = 1, 100
       select case (mod(i,15))
          case 0;        print *, 'FizzBuzz'
          case 3,6,9,12; print *, 'Fizz'
          case 5,10;     print *, 'Buzz'
          case default;  print *, i
       end select
    end do
 end program fizzbuzz_select

FreeBASIC[edit]

See FizzBuzz/Basic

Frege[edit]

gen n word = cycle (take (n - 1) (repeat "") ++ [word])
pattern = zipWith (++) (gen 3 "fizz") (gen 5 "buzz")
fizzbuzz = zipWith combine pattern [1..] where
    combine word number = if null word
                             then show number
                             else word
show $ take 100 fizzbuzz

Frink[edit]

for i = 1 to 100
{
   flag = false
   if i mod 3 == 0
   {
      flag = true
      print["Fizz"]
   }
   
   if i mod 5 == 0
   {
      flag = true
      print["Buzz"]
   }

   if flag == false
      print[i]

   println[]
}

FutureBasic[edit]

include "NSLog.incl"

long fizz, buzz, i

for i = 1 to 100
  fizz = (i mod 3 )
  buzz = (i mod 5 )
  if fizz + buzz == 0 then NSLog(@"FizzBuzz") : continue
  if fizz == 0 then NSLog(@"Fizz") : continue
  if buzz == 0 then NSLog(@"Buzz") : continue
  NSLog(@"%ld",i)
next i

HandleEvents

Output:

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

Fōrmulæ[edit]

Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation —i.e. XML, JSON— they are intended for storage and transfer purposes more than visualization and edition.

Programs in Fōrmulæ are created/edited online in its website.

In this page you can see and run the program(s) related to this task and their results. You can also change either the programs or the parameters they are called with, for experimentation, but remember that these programs were created with the main purpose of showing a clear solution of the task, and they generally lack any kind of validation.

Gambas[edit]

Click this link to run this code

Public Sub Main()
Dim siCount As Short
Dim sText As String

For siCount = 1 To 100
  sText = ""
  If siCount Mod 3 = 0 Then sText = "Fizz"
  If siCount Mod 5 = 0 Then sText = "Buzz"
  If siCount Mod 15 = 0 Then sText = "FizzBuzz"
  If sText Then Print sText Else Print siCount
Next

End

Output:

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

GAP[edit]

FizzBuzz := function()
	local i;
	for i in [1 .. 100] do
		if RemInt(i, 15) = 0 then
			Print("FizzBuzz\n");
		elif RemInt(i, 3) = 0 then
			Print("Fizz\n");
		elif RemInt(i, 5) = 0 then
			Print("Buzz\n");
		else
			Print(i, "\n");
		fi;
	od;
end;

GDScript[edit]

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()

Genyris[edit]

@prefix u "http://www.genyris.org/lang/utilities#"

def fizzbuzz (n)
    map-left ^((3 = 'fizz') (5 = 'buzz'))
        lambda (d)
            cond
                (equal? 0 (% n d!left))
                    d!right
                else
                    ''
                        

for n in (range 1 100)
    define fb (''(.join (fizzbuzz n)))
    u:format "%a\n"
        cond 
            (equal? fb '') 
                n
            else
                fb

GFA Basic[edit]

' Fizz Buzz
'
FOR i%=1 TO 100
  IF i% MOD 15=0
    PRINT "FizzBuzz"
  ELSE IF i% MOD 3=0
    PRINT "Fizz"
  ELSE IF i% MOD 5=0
    PRINT "Buzz"
  ELSE
    PRINT i%
  ENDIF
NEXT i%

Gleam[edit]

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)
  }
}

Go[edit]

switch/case approach[edit]

package main

import "fmt"

func main() {
    for i := 1; i <= 100; i++ {
        switch {
        case i%15==0:
            fmt.Println("FizzBuzz")
        case i%3==0:
            fmt.Println("Fizz")
        case i%5==0:
            fmt.Println("Buzz")
        default: 
            fmt.Println(i)
        }
    }
}

map approach[edit]

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])
    }
}

Golfscript[edit]

100,{)6,{.(&},{1$1$%{;}{4*35+6875*25base{90\-}%}if}%\or}%n*

Golo[edit]

module FizzBuzz

augment java.lang.Integer {
	function getFizzAndOrBuzz = |this| -> match {
		when this % 15 == 0 then "FizzBuzz"
		when this % 3 == 0 then "Fizz"
		when this % 5 == 0 then "Buzz"
		otherwise this
	}
}

function main = |args| {
  foreach i in [1..101] {
	println(i: getFizzAndOrBuzz())
  }
}

Gosu[edit]

for (i in 1..100) {
    
    if (i % 3 == 0 && i % 5 == 0) {
        print("FizzBuzz")
        continue
    }
    
    if (i % 3 == 0) {
        print("Fizz")
        continue
    }
    
    if (i % 5 == 0) {
        print("Buzz")
        continue
    }
    
    // default
    print(i)
    
}

One liner version (I added new lines to better readability but when you omit them it's one liner):

// 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)
}

Groovy[edit]

1.upto(100) { i -> println "${i % 3 ? '' : 'Fizz'}${i % 5 ? '' : 'Buzz'}" ?: i }

GW-BASIC[edit]

See FizzBuzz/Basic

Hare[edit]

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
		)!;
	};
};

Haskell[edit]

Variant directly implementing the specification:

fizzbuzz :: Int -> String
fizzbuzz x
  | f 15 = "FizzBuzz"
  | f 3 = "Fizz"
  | f 5 = "Buzz"
  | otherwise = show x
  where
    f = (0 ==) . rem x

main :: IO ()
main = mapM_ (putStrLn . fizzbuzz) [1 .. 100]
fizzbuzz :: Int -> String
fizzbuzz n =
  '\n' :
  if null (fizz ++ buzz)
    then show n
    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]

Does not perform the mod 15 step, extesible to arbitrary addtional tests, ex: [bar| n `mod` 7 == 0].

main = mapM_ (putStrLn . fizzbuzz) [1..100]

fizzbuzz n = 
    show n <|> [fizz| n `mod` 3 == 0] ++ 
               [buzz| n `mod` 5 == 0]

-- A simple default choice operator. 
-- Defaults if both fizz and buzz fail, concats if any succeed.
infixr 0 <|>
d <|> [] = d
_ <|> x = concat x

fizz = "Fizz"
buzz = "Buzz"

Alternate implementation using lazy infinite lists and avoiding use of "mod":

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"])

Or in terms (still without mod or rem) of an applicative ZipList:

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

or using an applicative test:

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

Using heavy artillery (needs the mtl package):

import Control.Monad.State
import Control.Monad.Trans
import Control.Monad.Writer

main = putStr $ execWriter $ mapM_ (flip execStateT True . fizzbuzz) [1..100]

fizzbuzz :: Int -> StateT Bool (Writer String) ()
fizzbuzz x = do
 when (x `mod` 3 == 0) $ tell "Fizz" >> put False
 when (x `mod` 5 == 0) $ tell "Buzz" >> put False
 get >>= (flip when $ tell $ show x)
 tell "\n"

Using guards plus where.

fizzBuzz :: (Integral a) => a -> String
fizzBuzz i
  | fizz && buzz = "FizzBuzz"
  | fizz         = "Fizz"
  | buzz         = "Buzz"
  | otherwise    = show i
  where fizz = i `mod` 3 == 0
        buzz = i `mod` 5 == 0

main = mapM_ (putStrLn . fizzBuzz) [1..100]

An elegant solution exploiting monoidal and applicative properties of functions:

import Data.Monoid

fizzbuzz = max
       <$> show
       <*> "fizz" `when` divisibleBy 3
       <>  "buzz" `when` divisibleBy 5
       <>  "quxx" `when` divisibleBy 7
  where
    when m p x = if p x then m else mempty
    divisibleBy n x = x `mod` n == 0

main = mapM_ (putStrLn . fizzbuzz) [1..100]

And pattern matching approach:

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]

Generalised solution:

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]

hexiscript[edit]

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

HicEst[edit]

DO i = 1, 100
  IF(     MOD(i, 15) == 0 ) THEN
    WRITE() "FizzBuzz"
  ELSEIF( MOD(i, 5) == 0 ) THEN
    WRITE() "Buzz"
  ELSEIF( MOD(i, 3) == 0 ) THEN
    WRITE() "Fizz"
  ELSE
    WRITE() i
  ENDIF
ENDDO

Alternatively:

CHARACTER string*8

DO i = 1, 100
  string = " "
  IF( MOD(i, 3) == 0 ) string = "Fizz"
  IF( MOD(i, 5) == 0 ) string = TRIM(string) // "Buzz"
  IF( string == " ") WRITE(Text=string) i
  WRITE() string
ENDDO

HolyC[edit]

U8 i;
for (i = 1; i <= 100; i++) {
  if (!(i % 15))
    Print("FizzBuzz");
  else if (!(i % 3))
    Print("Fizz");
  else if (!(i % 5))
    Print("Buzz");
  else
    Print("%d", i);
  Print("\n");
}

Hoon[edit]

:-  %say
|=  [^ ~ ~]
  :-  %noun
  %+  turn   (gulf [1 101])
  |=  a=@
    =+  q=[=(0 (mod a 3)) =(0 (mod a 5))]
    ?+  q  <a>
      [& &]  "FizzBuzz"
      [& |]  "Fizz"
      [| &]  "Buzz"
    ==

Huginn[edit]

import Algorithms as algo;

main( argv_ ) {
	if ( size( argv_ ) < 2 ) {
		throw Exception( "usage: fizzbuzz {NUM}" );
	}
	top = integer( argv_[1] );
	for ( i : algo.range( 1, top + 1 ) ) {
		by3 = ( i % 3 ) == 0;
		by5 = ( i % 5 ) == 0;
		if ( by3 ) {
			print( "fizz" );
		}
		if ( by5 ) {
			print( "buzz" );
		}
		if ( ! ( by3 || by5 ) ) {
			print( i );
		}
		print( "\n" );
	}
	return ( 0 );
}

Hy[edit]

(for [i (range 1 101)] (print (cond
  [(not (% i 15)) "FizzBuzz"]
  [(not (% i  5)) "Buzz"]
  [(not (% i  3)) "Fizz"]
  [True           i])))

i[edit]

software {
	for each 1 to 100		
		if i % 15 = 0
			print("FizzBuzz")
		else if i % 3 = 0
			print("Fizz")
		else if i % 5 = 0
			print("Buzz")
		else
			print(i)
		end
	end
}

Icon and Unicon[edit]

# straight-forward modulo tester
procedure main()
    every i := 1 to 100 do
        if i % 15 = 0 then
            write("FizzBuzz")
        else if i % 5 = 0 then
            write("Buzz")
        else if i % 3 = 0 then
            write("Fizz")
        else
            write(i)
end
# 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
# idiomatic modulo tester, 2nd alternative
procedure main()
    every i := 1 to 100 do
        write(case 0 of {
                 i % 15 : "FizzBuzz"
                 i % 5  : "Buzz"
                 i % 3  : "Fizz"
                 default: i
        })
end
# straight-forward buffer builder
procedure main()
    every i := 1 to 100 do {
        s := ""
        if i % 3 = 0 then
            s ||:= "Fizz"
        if i % 5 = 0 then
            s ||:= "Buzz"
        if s == "" then
            s := i
        write(s)
    }
end
# 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
# idiomatic buffer builder, 2nd alternative
procedure main()
    every i := 1 to 100 do {
        s   := if i%3 = 0 then "Fizz" else ""
        s ||:= if i%5 = 0 then "Buzz"
        write(("" ~= s) | i)
    }
end

Idris[edit]

partial
fizzBuzz : Nat -> String
fizzBuzz n = if (n `modNat` 15) == 0 then "FizzBuzz"
             else if (n `modNat` 3) == 0 then "Fizz"
             else if (n `modNat` 5)  == 0 then "Buzz"
             else show n

main : IO ()
main = sequence_ $ map (putStrLn . fizzBuzz) [1..100]

Inform 6[edit]

[ Main i;
    for (i = 1: i <= 100: i++) {
        if (i % 3 == 0)
            print "Fizz";
        if (i % 5 == 0)
            print "Buzz";
        if (i % 3 ~= 0 && i % 5 ~= 0)
            print i;

        print "^";
    }
];

Inform 7[edit]

(Does not work in the current version of Inform 7)

Home is a room.

When play begins:
	repeat with N running from 1 to 100:
		let printed be false;
		if the remainder after dividing N by 3 is 0:
			say "Fizz";
			now printed is true;
		if the remainder after dividing N by 5 is 0:
			say "Buzz";
			now printed is true;
		if printed is false, say N;
		say ".";
	end the story.

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

The space is a room.  An item is a kind of thing.  In the space are 100 items.

To say the name:
	let the count be the number of items carried by the player;
	say "[if the count is the count to the nearest 15]fizzbuzz.[otherwise if the count is the count to the nearest 3]fizz.[otherwise if the count is the count to the nearest 5]buzz.[otherwise][the count in words].".

To count:
	if an item is in the space
	begin;
		let the next one be a random item in the space; silently try taking the next one;
		say "[the name]" in sentence case;
		count;
		end the story;
	end if.
		
When play begins: count.  Use no scoring.

Io[edit]

Here's one way to do it:

for(a,1,100,
   if(a % 15 == 0) then(
      "FizzBuzz" println
   ) elseif(a % 3 == 0) then(
      "Fizz" println
   ) elseif(a % 5 == 0) then(
      "Buzz" println
   ) else (
      a println
   )
)

And here's a port of the Ruby version, which I personally prefer:

a := 0; b := 0
for(n, 1, 100,
    if(a = (n % 3) == 0, "Fizz" print);
    if(b = (n % 5) == 0, "Buzz" print);
    if(a not and b not, n print);
    "\n" print
)

And here is another more idiomatic version:

for (n, 1, 100,
    fb := list (
        if (n % 3 == 0, "Fizz"),
        if (n % 5 == 0, "Buzz")) select (isTrue)
    
    if (fb isEmpty, n, fb join) println
)

Ioke[edit]

(1..100) each(x,
  cond(
    (x % 15) zero?, "FizzBuzz" println,
    (x % 3) zero?, "Fizz" println,
    (x % 5) zero?, "Buzz" println
  )
)

Iptscrae[edit]

; FizzBuzz in Iptscrae
1 a =
{
   "" b =
   { "fizz" b &= } a 3 % 0 == IF
   { "buzz" b &= } a 5 % 0 == IF
   { a ITOA LOGMSG } { b LOGMSG } b STRLEN 0 == IFELSE
   a ++
}
{ a 100 <= } WHILE

IS-BASIC[edit]

See FizzBuzz/Basic

J[edit]

Perhaps the most concise approach would be >((2#.3 q:15&+.){(|.(;~,&;);:'Fizz Buzz');~":)&>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:

   classify =: +/@(1 2 * 0 = 3 5&|~)
   (":@]`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_) @. classify "0)  >:i.100

Solution 0

> }. (<'FizzBuzz') (I.0=15|n)} (<'Buzz') (I.0=5|n)} (<'Fizz') (I.0=3|n)} ":&.> n=: i.101

Solution 1

Fizz=: 'Fizz' #~ 0 = 3&|
Buzz=: 'Buzz' #~ 0 = 5&|
FizzBuzz=: ": [^:('' -: ]) Fizz,Buzz

FizzBuzz"0 >: i.100

Solution 2 (has taste of table-driven template programming)

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

Solution 3 (depends on an obsolete feature of @ in f`g`h@p)

'`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

Solution 4 (relatively concise):

   ;: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...

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

   i.10
0 1 2 3 4 5 6 7 8 9
   (3 5 |/ ])i.10
0 1 2 0 1 2 0 1 2 0
0 1 2 3 4 0 1 2 3 4
   (0=3 5 |/ ])i.10
1 0 0 1 0 0 1 0 0 1
1 0 0 0 0 1 0 0 0 0
   (;:'Fizz Buzz')
┌────┬────┐
FizzBuzz
└────┴────┘
   ((;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
┌────┬┬┬────┬┬────┬────┬┬┬────┐
Fizz│││Fizz││    Fizz│││Fizz
├────┼┼┼────┼┼────┼────┼┼┼────┤
Buzz│││    ││Buzz    │││    
└────┴┴┴────┴┴────┴────┴┴┴────┘
   ([: ,&.>/ (;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
┌────────┬┬┬────┬┬────┬────┬┬┬────┐
FizzBuzz│││Fizz││BuzzFizz│││Fizz
└────────┴┴┴────┴┴────┴────┴┴┴────┘
   (":&.>)i.10
┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐
0123456789
└─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘
   (":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
┌────────┬─┬─┬────┬─┬────┬────┬─┬─┬────┐
FizzBuzz12Fizz4BuzzFizz78Fizz
└────────┴─┴─┴────┴─┴────┴────┴─┴─┴────┘
   }.(":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
┌─┬─┬────┬─┬────┬────┬─┬─┬────┐
12Fizz4BuzzFizz78Fizz
└─┴─┴────┴─┴────┴────┴─┴─┴────┘
   ;:inv}.(":&.> [^:(0 = #@])&.> [: ,&.>/ (;:'Fizz Buzz') #&.>~0=3 5 |/ ])i.10
1 2 Fizz 4 Buzz Fizz 7 8 Fizz

Janet[edit]

(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)))

Java[edit]

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);
            }
        }
    }
}

Or:

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++;
        }
    }
}

Or:

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++;
        }
    }
}

Or:

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)
        ;
    }
}

Or:

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)
       ;
    }
}

JavaScript[edit]

ES5[edit]

var fizzBuzz = function () {
  var i, output;
  for (i = 1; i < 101; i += 1) {
    output = '';
    if (!(i % 3)) { output += 'Fizz'; }
    if (!(i % 5)) { output += 'Buzz'; }
    console.log(output || i);//empty string is false, so we short-circuit
  }
};

Alternate version with ghetto pattern matching

for (var i = 1; i <= 100; i++) {
  console.log({
    truefalse: 'Fizz', 
    falsetrue: 'Buzz', 
    truetrue: 'FizzBuzz'
  }[(i%3==0) + '' + (i%5==0)] || i)
}

Or very tersely:

for(i=1;i<101;i++)console.log((x=(i%3?'':'Fizz')+(i%5?'':'Buzz'))?x:i);

Or with even less characters:

for(i=1;i<101;i++)console.log((i%3?'':'Fizz')+(i%5?'':'Buzz')||i)

Or, in a more functional style, without mutations

(function rng(i) {
    return i ? rng(i - 1).concat(i) : []
})(100).map(
    function (n) {
        return n % 3 ? (
            n % 5 ? n : "Buzz"
        ) : (
            n % 5 ? "Fizz" : "FizzBuzz"
        )
    }
).join(' ')

ES6[edit]

(() => {

    // FIZZBUZZ --------------------------------------------------------------

    // fizzBuzz :: Int -> String
    const fizzBuzz = n =>
        caseOf(n, [
            [x => x % 15 === 0, "FizzBuzz"],
            [x => x % 3 === 0, "Fizz"],
            [x => x % 5 === 0, "Buzz"]
        ], n.toString());

    // GENERIC FUNCTIONS -----------------------------------------------------

    // caseOf :: a -> [(a -> Bool, b)] -> b -> b
    const caseOf = (e, pvs, otherwise) =>
        pvs.reduce((a, [p, v]) =>
            a !== otherwise ? a : (p(e) ? v : a), otherwise);

    // enumFromTo :: Int -> Int -> [Int]
    const enumFromTo = (m, n) =>
        Array.from({
            length: Math.floor(n - m) + 1
        }, (_, i) => m + i);

    // map :: (a -> b) -> [a] -> [b]
    const map = (f, xs) => xs.map(f);

    // unlines :: [String] -> String
    const unlines = xs => xs.join('\n');

    // TEST ------------------------------------------------------------------
    return unlines(
        map(fizzBuzz, enumFromTo(1, 100))
    );
})();

A functional implementation:

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'))


Or composing generic functions, and without use of modulo (or other) numeric tests:

Translation of: Python
Translation of: Haskell
(() => {
    '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();
})();

Joy[edit]

The following program first defines a function "out", that handles the Fizz / Buzz logic, and then loops from 1 to 100 mapping the function onto each number, and printing ("put") the output.

DEFINE out == [[[15 rem null] "FizzBuzz"]
[[ 3 rem null] "Fizz"]
[[ 5 rem null] "Buzz"]
[]] cond
[putchars pop] [put] ifstring '\n putch.

100 [] [out] primrec.

jq[edit]

range(1;101)
  | if   . % 15 == 0 then "FizzBuzz"
    elif . % 5  == 0 then "Buzz"
    elif . % 3  == 0 then "Fizz"
    else .
    end

Another solution:

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

Julia[edit]

Works with: Julia version 1.8.5

One basic solution:

for i in 1:100
    if i % 15 == 0
        println("FizzBuzz")
    elseif i % 3 == 0
        println("Fizz")
    elseif i % 5 == 0
        println("Buzz")
    else
        println(i)
    end
end

Another possible solution:

collect(i % 15 == 0 ? "FizzBuzz" : i % 5 == 0 ? "Buzz" : i % 3 == 0 ? "Fizz" : i for i in 1:100) |> println

A 3rd possible solution:

fb(i::Integer) = "Fizz" ^ (i % 3 == 0) * "Buzz" ^ (i % 5 == 0) * string(i) ^ (i % 3 != 0 && i % 5 != 0)
for i in 1:100 println(fb(i)) end

A 4th one:

println.(map(fb, 1:100))

A fifth (DRY, Don't Repeat Yourself) possible solution:

for i in 1:100
    msg = "Fizz" ^ (i % 3 == 0) * "Buzz" ^ (i % 5 == 0)
    println(isempty(msg) ? i : msg)
end

K[edit]

Solution 0[edit]

`0:\:{:[0=#a:{,/$(:[0=x!3;"Fizz"];:[0=x!5;"Buzz"])}@x;$x;a]}'1_!101

Solution 1[edit]

  fizzbuzz:{:[0=x!15;`0:,"FizzBuzz";0=x!3;`0:,"Fizz";0=x!5;`0:,"Buzz";`0:,$x]}
  fizzbuzz' 1+!100

Solution 2[edit]

fizzbuzz:{
  v:1+!x
  i:(&0=)'v!/:3 5 15
  r:@[v;i 0;{"Fizz"}]
  r:@[r;i 1;{"Buzz"}]
  @[r;i 2;{"FizzBuzz"}]}

`0:$fizzbuzz 100

Solution 3[edit]

For kona:
{,/$(s;x)@~#s:`Fizz`Buzz@&~x!'3 5}'1+!30

For k6 and oK, change x!'3 5 to 3 5!'x.

Kamailio Script[edit]

To run it, send a SIP message to the server and FizzBuzz will appear in the logs.

This will only work up to 100 because Kamailio terminates all while loops after 100 iterations.

# FizzBuzz
log_stderror=yes
loadmodule "pv"
loadmodule "xlog"
 
route {
    $var(i) = 1;
    while ($var(i) <= 1000) {
        if ($var(i) mod 15 == 0) {
            xlog("FizzBuzz\n");
        } else if ($var(i) mod 5 == 0) {
            xlog("Buzz\n");
        } else if ($var(i) mod 3 == 0) {
            xlog("Fizz\n");
        } else {
            xlog("$var(i)\n");
        }
        $var(i) = $var(i) + 1;
    }
}

Kaya[edit]

// fizzbuzz in Kaya
program fizzbuzz;

Void fizzbuzz(Int size) {
    for i in [1..size] {
        if (i % 15 == 0) {
            putStrLn("FizzBuzz");
        } else if (i % 5 == 0) {
            putStrLn("Buzz");
        } else if (i % 3 == 0) {
            putStrLn("Fizz");
        } else {
            putStrLn( string(i) );
        }
    }
}

Void main() {
    fizzbuzz(100);
}

KL1[edit]

:- 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([]).

Klong[edit]

{:[0=x!15;:FizzBuzz:|0=x!5;:Buzz:|0=x!3;:Fizz;x]}'1+!100

Kotlin[edit]

Imperative solution[edit]

fun fizzBuzz() {
    for (number in 1..100) {
        println(
            when {
                number % 15 == 0 -> "FizzBuzz"
                number % 3 == 0 -> "Fizz"
                number % 5 == 0 -> "Buzz"
                else -> number
            }
        )
    }
}

Functional solution 1[edit]

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
    fun buzz(x: Any) = if (x is Int && x.toInt() % 5 == 0) "Fizz" else x

    (1..100).map { fizzBuzz(it) }.map { fizz(it) }.map { buzz(it) }.forEach { println(it) }
}

Functional solution 2[edit]

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
    fun none(x: Pair<Int, StringBuilder>) = if(x.second.isBlank()) x.second.apply { append(x.first) } else x.second

    (1..100).map { Pair(it, StringBuilder()) }
            .map { fizz(it) }
            .map { buzz(it) }
            .map { none(it) }
            .forEach { println(it) }
}

Short version with mapOf[edit]

fun fizzBuzz() {
    (1..100).forEach { println(mapOf(0 to it, it % 3 to "Fizz", it % 5 to "Buzz", it % 15 to "FizzBuzz")[0]) }
}

KQL[edit]

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)
    )

KSI[edit]

`plain
[1 100] `for pos : n ~
	out = []
	n `mod 3 == 0 ? out.# = 'Fizz' ;
	n `mod 5 == 0 ? out.# = 'Buzz' ;
	(out `or n) #write_ln #
;

LabVIEW[edit]

This image is a VI Snippet, an executable image of LabVIEW code. The LabVIEW version is shown on the top-right hand corner. You can download it, then drag-and-drop it onto the LabVIEW block diagram from a file browser, and it will appear as runnable, editable code.
LabVIEW FizzBuzz.png

Lambdatalk[edit]

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.

Lang[edit]

$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
}

langur[edit]

for .i of 100 {
    writeln given(0; .i rem 15: "FizzBuzz"; .i rem 5: "Buzz"; .i rem 3: "Fizz"; .i)
}
Works with: langur version 0.8.1
for .i of 100 {
    writeln if(.i div 15: "FizzBuzz"; .i div 5: "Buzz"; .i div 3: "Fizz"; .i)
}

Lasso[edit]

with i in generateSeries(1, 100)
select ((#i % 3 == 0 ? 'Fizz' | '') + (#i % 5 == 0 ? 'Buzz' | '') || #i)

LaTeX[edit]

Library: ifthen
Library: 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.

\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}

Lean[edit]

Lean 4:

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


Liberty BASIC[edit]

See FizzBuzz/Basic

LIL[edit]

# 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
}
Output:
prompt$ lil fizzbuzz.lil | sed -n '1,16p'
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16

LiveCode[edit]

repeat with i = 1 to 100
    switch
        case i mod 15 = 0
            put "FizzBuzz" & cr after fizzbuzz
            break
        case i mod 5 = 0
            put "Buzz" & cr after fizzbuzz
            break
        case i mod 3 = 0
            put "Fizz" & cr after fizzbuzz
            break
        default
            put i & cr after fizzbuzz
    end switch 
end repeat
put fizzbuzz

LiveScript[edit]

See: http://livescript.net/blog/fizzbuzzbazz.html

[1 to 100] map -> [k + \zz for k, v of {Fi: 3, Bu: 5} | it % v < 1] * '' || it

LLVM[edit]

; 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)"}

Lobster[edit]

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

[edit]

to fizzbuzz :n
  output cond [ [[equal? 0 modulo :n 15] "FizzBuzz]
                [[equal? 0 modulo :n  5] "Buzz]
                [[equal? 0 modulo :n  3] "Fizz]
                [else :n] ]
end

repeat 100 [print fizzbuzz #]

"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:

to fizzbuzz :n
 make "c "
  if equal? 0 modulo :n 5 [make "c "Buzz]
  if equal? 0 modulo :n 3 [make "c word "Fizz :c]
 output ifelse equal? :c " [:n] [:c]
end

repeat 100 [print fizzbuzz repcount]

Lhogho can use the above code, except that 'modulo' must be replaced with 'remainder'.

LOLCODE[edit]

See FizzBuzz/EsoLang

LSE[edit]

1* FIZZBUZZ en L.S.E. 
10 CHAINE FB
20 FAIRE 45 POUR I_1 JUSQUA 100 
30 FB_SI &MOD(I,3)=0 ALORS SI &MOD(I,5)=0 ALORS 'FIZZBUZZ' SINON 'FIZZ' SINON SI &MOD(I,5)=0 ALORS 'BUZZ' SINON ''
40 AFFICHER[U,/] SI FB='' ALORS I SINON FB
45*FIN BOUCLE
50 TERMINER
100 PROCEDURE &MOD(A,B) LOCAL A,B
110 RESULTAT A-B*ENT(A/B)

Lua[edit]

If/else Ladder[edit]

for i = 1, 100 do
	if i % 15 == 0 then
		print("FizzBuzz")
	elseif i % 3 == 0 then
		print("Fizz")
	elseif i % 5 == 0 then
		print("Buzz")
	else
		print(i)
	end
end

Concatenation[edit]

for i = 1, 100 do
	output = ""
	if i % 3 == 0 then
		output = output.."Fizz"
	end
	if i % 5 == 0 then
		output = output.."Buzz"
	end
	if(output == "") then
		output = i
	end
	print(output)
end

Quasi bit field[