Skip to content
Justice Tech School

Practice: FizzBuzz

Combine a range with when.

Example
for (i in 1..15) {
    print(when {
        i % 15 == 0 -> "FizzBuzz"
        i % 3 == 0 -> "Fizz"
        i % 5 == 0 -> "Buzz"
        else -> i.toString()
    } + " ")
}

Exercise

Branch without a subject.

when  { }

Quiz Test

What does when without an argument do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.