Skip to content

Instantly share code, notes, and snippets.

@zacps
Last active May 10, 2022 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zacps/a2c65d54ab4e5221cdb6a13629c0d15b to your computer and use it in GitHub Desktop.
Save zacps/a2c65d54ab4e5221cdb6a13629c0d15b to your computer and use it in GitHub Desktop.
Fizzbuzz in golang using a switch statement
package main
import "fmt"
func fizzbuzz(max int) {
for i := 1; i < max; i++ {
switch {
case (i%3 == 0) && (i%5 == 0):
+ fmt.Println("FizzBuzz")
case i%3 == 0:
fmt.Println("Fizz")
case i%5 == 0:
fmt.Println("Buzz")
default:
fmt.Println(i)
}
}
}
func main() {
fizzbuzz(100)
}
Copy link

ghost commented Feb 21, 2021

Beautiful and much simpler than most fizzbuzz solutions out there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment