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

Cant figure out how to do 2nd part of task.

I know the 1st task is

while counter < numbers.count {
    print(numbers[counter])
    counter++
}

but I can not figure out the 2nd part which is this... Using the value of counter as an index value, retrieve each value from the array and add it to the value of sum.

For example: sum = sum + newValue. Or you could use the compound addition operator sum += newValue where newValue is the value retrieved from the array.

theodore eisensøe
theodore eisensøe
1,107 Points

i am pretty sure this is what you are looking for,

while counter < 1 { print(counter) counter++ }

I tried that and it did not work... Im going to keep messing with it

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Shane,

You're already correctly using counter as an index. Now, instead of printing that value, add it to the variable sum:

while counter < numbers.count {
    sum += numbers[counter]
    counter++
}

Make sense?

Cheers :beers:

Greg

Yes it makes perfect sense. I knew it would be something that i was just over looking.

Thank You!

Shane.