FizzBuzz in Go
The classic screening exercise for loops and conditionals.
func fizzbuzz(n int) {
for i := 1; i <= n; 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)
}
}
}
Keywords and builtins used here
casedefaultforfuncintswitch
The run, in numbers
- Lines
- 14
- Characters to type
- 197
- Tokens
- 71
- Three-star pace
- 85 tpm
At the three-star pace of 85 tokens a minute, this run takes about 50 seconds.
Step 4 of 4 in Control flow, step 9 of 30 in Language basics.