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 2.0 Collections and Control Flow Control Flow With Loops Working with Loops

While 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 }

while.swift
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
}

I get the same error which is weird, It looks like a treehouse compiler issue

1 Answer

Lee Nolan
Lee Nolan
21,690 Points

Hi, 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.

Yep, 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.