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 trialHarry Stebbings
1,097 PointsHey guys, really struggling here. Any ideas where I am going wrong?
var index = 0 while index < numbers { println(numbers[Index]) index++
Is there anything wrong with this?
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var index = 0
while index < numbers {
println(numbers[Index])
index++
}
1 Answer
Gareth Borcherds
9,372 Pointsnumbers is a NSArray so when you try and compare it to index < numbers you aren't saying less than a number. You need to get the count of the array. Try this.
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var index = 0
while index < numbers.count {
println(numbers[index])
index++
}
Harry Stebbings
1,097 Pointsit is still not working! I did try that previously but gave it another go when you recommended it!
Gareth Borcherds
9,372 PointsWhat error are you receiving? Also, you had an incorrect spelling of index where you had a capital I for Index in your print statement. I fixed that in my code above. I tried this in a playground and it's working.
Gareth Borcherds
9,372 PointsGareth Borcherds
9,372 PointsPlease only post once.