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

Yingzhou Xia
Yingzhou Xia
Courses Plus Student 475 Points

I dont know how you extract the number constant array from the number constants to apply to the newValue

Can some one please explain this thank you ! I am lost, how do you implement the while loop extracting the array and set it to "newValue"

let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0
while counter<numbers.count{counter++}
sum += 
// Enter your code below

1 Answer

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey Yingzhou,

you don't necessarily have to use another variable/constant like newValue . All you have to do is get each item of the numbers array which you can do by accessing it with the counter variable as an index inside of brackets. You then have to add each item's value to the sum variable.

Like so:

let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0
while counter < numbers.count {
    sum += numbers[counter]

I hope that helps! :)

Jordi Gámez
Jordi Gámez
3,568 Points

Hi Tobias,

Remember to use counter += 1 instead of counter++ because it is going to be deprecated from Swift 3.0.