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 trialpranjoshi
6,332 PointsWhile loop Objective exercise
Hello,
I am getting following error message while attempting Objective exercise. I have pasted code below. Not sure where error is. I am incrementing counter variable inside the loop.
Bummer! Make sure you increment the counter variable inside the loop! If you don't, the code loops infinitely and the challenge times out!
let numbers = [2,8,1,16,4,3,9] var sum = 0 var counter = 0
// Enter your code below
while counter < numbers.count { counter += 1 }
let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0
// Enter your code below
while counter < numbers.count {
counter += 1
}
1 Answer
Lee Nolan
21,690 PointsHi, your code should work, and would in Xcode. I think the Treehouse compiler is expecting you to use the (now deprecated for Swift 3) increment operator- counter++ - rather than the compound assignment operator as you have done.
pranjoshi
6,332 PointsYep, I tried in XCode and it worked.
So I wasn't sure what wrong in my code and it is not working in Treehouse compiler.
Safwat Shenouda
12,362 PointsSafwat Shenouda
12,362 PointsI get the same error which is weird, It looks like a treehouse compiler issue