Download

← Examples

fizzbuzz

The numbers from 1 to 100, with Fizz, Buzz and FizzBuzz for the multiples of 3, of 5 and of both.

examples/fizzbuzz in the repository.

// FizzBuzz: print 1..=100, replacing multiples of 3 with "Fizz", multiples
// of 5 with "Buzz", and multiples of both with "FizzBuzz".

module "main"

import "std/io"

main :: fn() -> i32 {
    for n in 1..=100 {
        if n % 15 == 0 {
            println("FizzBuzz")
        } else if n % 3 == 0 {
            println("Fizz")
        } else if n % 5 == 0 {
            println("Buzz")
        } else {
            println(n)
        }
    }
    return 0
}