Skip to content

Instantly share code, notes, and snippets.

@enomoto
Created September 21, 2015 05:08
Show Gist options
  • Save enomoto/a1563aedffd6401d3f71 to your computer and use it in GitHub Desktop.
Save enomoto/a1563aedffd6401d3f71 to your computer and use it in GitHub Desktop.
FizzBuzz in Swift
func fizzBuzz(num: Int) -> String {
switch num {
case _ where num % 15 == 0:
return "FizzBuzz"
case _ where num % 3 == 0:
return "Fizz"
case _ where num % 5 == 0:
return "Buzz"
default:
return num.description
}
}
for num in 0...20 {
print(fizzBuzz(num))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment