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 trialkirstie perez
312 PointsWhile loop not working. Please help.
Guys, this code isn't working for some reason. Please answer if you see anything wrong, cause' i can't see anything wrong. Thanks! :)
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var index = 0
while index < numbers.count{
println(numbers.count[index])
++index
}
4 Answers
Dennis Parussini
Treehouse Project ReviewerYes, it should be index++. ++index increments the index before the check for index < numbers.count. This way your array would be out of range.
arnavthecoder
3,453 PointsHello,
I believe it should be index++.
Also can I see the error?
Walter Recinos
2,077 PointsLike the instructor said: when you write ++index in a loop that starts conditioning the "index" value to be less than numbers.count, there is a point where index value = 10 and then turns into 11 inside the loop... which is not supposed to happen since 11 is not lower than numbers.count..
English is not my main language so i apologize if my answer was not clear.
kirstie perez
312 PointsThanks to all who answered. You helped a lot.
arnavthecoder
3,453 PointsNo problem