Skip to content

Instantly share code, notes, and snippets.

@shakyra
Created May 21, 2019 18:59
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 shakyra/a4323423daf0b9ba6dae38b5a90b2536 to your computer and use it in GitHub Desktop.
Save shakyra/a4323423daf0b9ba6dae38b5a90b2536 to your computer and use it in GitHub Desktop.
My nooby attempt at fizzBuzz using for where loops
var i: Int = 3
var fizz: String = "Fizz"
var buzz: String = "Buzz"
var fizzBuzz: String = "FizzBuzz"
for i in 1...100 where i % 3 == 0 {
print(fizz)
}
for i in 1...100 where i % 5 == 0 {
print(buzz)
}
for i in 1...100 where i % 3 == 0 && i % 5 == 0 {
print(fizzBuzz)
}
@shakyra
Copy link
Author

shakyra commented May 26, 2019

for i in 1...15 {

if i % 3 == 0 && i % 5 == 0 {
    print("FIZZ BUZZ")
}

else if i % 3 == 0 {
    print("FIZZ")
}
    
else if i % 5 == 0 {
    print("BUZZ")
}

else {
    print(i)
}

}

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