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 While and Do-While Loop

Jun Da Ma
Jun Da Ma
2,266 Points

for the while loop eg. why is it that if index ++ is written on the same line as println, then the code will not work

Is it becaues the syntax requirement is such that each statement has to be written on a new line?

Can you post the code you're talking about?

2 Answers

Dennis Parussini
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dennis Parussini
Treehouse Project Reviewer

Easy, each code statement has to start on a new line. You can write multiple statements on one line, seperated by a ; but I wouldn't recommend that as your code will get unreadable over time.

This is what I made my while statement look like, and works perfectly, since index is being incremented AFTER 'println()' is executed since I am incrementing as a suffix:

while index < todo.count {

println(todo[index++])

}