Skip to content

Instantly share code, notes, and snippets.

@gjones
Last active February 10, 2017 02:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjones/bd623fad47f315270a4a to your computer and use it in GitHub Desktop.
Save gjones/bd623fad47f315270a4a to your computer and use it in GitHub Desktop.
Simple solution to the Fizzbuzz question in Swift.
// Write a program that prints the numbers from 1 to 100.
// For multiples of three print "Fizz" instead of the number
// For multiples of five print "Buzz". For numbers which
// For multiples of both three and five print "FizzBuzz".
for number in 1...100 {
if (number % 15 == 0) {
println("FizzBuzz")
}
else if (number % 3 == 0) {
println("Fizz")
}
else if (number % 5 == 0) {
println("Buzz")
}
else {
println(number)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment