Skip to content

Instantly share code, notes, and snippets.

@chrisz100
Last active August 29, 2015 14:13
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 chrisz100/401de6b76e8ed0fcee51 to your computer and use it in GitHub Desktop.
Save chrisz100/401de6b76e8ed0fcee51 to your computer and use it in GitHub Desktop.
Simple FizzBuzz in golang
package main
import "fmt"
func main() {
for i := 1; i <= 100; i++ {
switch {
case i%3 == 0:
// check if matching i%5 as well (FizzBuzz)
if i%5 == 0 {
fmt.Println("FizzBuzz")
} else {
fmt.Println("Fizz")
}
case i%5 == 0:
// Wont apply to i%3 and i%5 because switch case already matched 3
fmt.Println("Buzz")
default:
// no match
fmt.Println(i)
}
}
}
@chrisz100
Copy link
Author

Note: I'm not using i%15 here just to make it more logical to people not knowing that you can multiply 3 and 5 if you want to check that both applies 😄

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