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-Condition-Increment

Why place i++ infront of println?

in the while loop index++ after println but now why is i++ before println and it's outside the curly brackets?

2 Answers

C H
C H
6,587 Points

The for loop looks a bit different but functions exactly like the while loop in the video. They do the same thing. So you have: for index; condition; increment {code here}. The index variable is set, the condition is checked, and then the code is run. After the code is run, the increment takes affect, the condition is then checked again, and this process repeats until the condition is no longer True.

Got it. Thank you.