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! While you're at it, check out some resources Treehouse students have shared here.

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 For-In Loop

for-in format

Do you have to put the for-in function on multiple lines?

at 2:16 he spaces the function over 3 lines, and it seems like this is the only way for it to work whenever I do it myself. He does not mention this being a requirement.

So I am wondering if my computer is just acting up, or this is the way you have to set up For-In functions.

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Don,

Whitespace is not important to Swift, so the three lines are not a requirement. I wouldn't recommend it, but you could write a for-in loop like this if you really wanted to:

hardToRead.swift
for item in todo{println(item)}

I doubt your computer is acting up - it's probably something else that's causing your problem.

That said, it's a very good idea, and is considered a best practice to indent your code for easier reading. Amit's formatting is what you should follow for readability.

Best,

-Greg

Thank you Greg! I dont know what's going on with it.
Now that I go in and take away the indents, after the fact, it works. Probably just my dumb luck.