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
Taseen Anwar
296 PointsWhile and do-While Loop: Swift
when he wrote:
var index = 0 while index < todo.count { println(todo[index]) index++ }
What does this mean? I have understood the course so far up until this point. What is going on?
1 Answer
Alexander Bakushkin
2,288 PointsIt means:
We have an array "todo" with exact quantity of items in it, for example, 5. Loop starts from index = 0, which is less than 5 therefore run println element of array "todo" with index 0, then we increment index by 1. And so on...
Like this:
var index = 0 while 0 < 5 {
println(todo[0])
index = 1
}
Then starts another loop with index = 1...