Last active
August 29, 2015 14:13
-
-
Save chrisz100/401de6b76e8ed0fcee51 to your computer and use it in GitHub Desktop.
Simple FizzBuzz in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 😄