Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Basics (retired) Control Flow Exercise: FizzBuzz Generator

The exact SAME code for my "if-conditional" sometimes WORKS, and sometimes DOESN'T work.

I was thinking of an alternative implementation for the FizzBuzz game, so I chose the C-style "for-iterator" and an "if-conditional".

Strangely enough, the code didn't work. So I rewrote the two "else if" statement, and voilà, it worked. The exact same code.

Then I pasted the old code over it, and even though nothing changed, it threw up 3 errors.

One works, one doesn't. What the hell?!



1 Answer

Max Hirsh
Max Hirsh
16,773 Points

Hey there, so I could be wrong about this, but using the style I found in this control flow example from apple:


it looks like swift likes you to start the else if statements on the same line as the end bracket for the previous control flow operator (if or else if). I could be wrong but in my experience xcode is pretty finicky about how you style/space things.