for (var i = 1; i <= 100; ++i) {
var fizzBuzz = ""
if i % 3 == 0 {
fizzBuzz += "Fizz"
}
if i % 5 == 0 {
fizzBuzz += "Buzz"
}
if fizzBuzz == "" {
fizzBuzz += "\(i)"
}
println(fizzBuzz)
}
I don't really like comparing strings with ==
, but apparently, that's how you do it in Swift (and there's not another option).
The parenthesis in if
statements are optional in Swift. Should that be a thing, or should we stick with them? The curly-braces were optional in Objective-C (and lots of programming languages) but they're not in Swift. Despite their former optionality, I never thought it was a good idea to not use them--is it a good idea to not use parenthesis here?
Not explicitly declaring the type of variable is now a thing in Swift (although the variable still has an explicit type, it's just implicitly determined). Is it okay to let the type be implicitly determined, or should we stick with explicitly declaring the type?