Last active
May 10, 2022 22:54
-
-
Save zacps/a2c65d54ab4e5221cdb6a13629c0d15b to your computer and use it in GitHub Desktop.
Fizzbuzz in golang using a switch statement
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 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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Beautiful and much simpler than most fizzbuzz solutions out there.