Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Collections and Control Flow Control Flow With Loops Working With Loops

I am stuck at this step. Do I need to make a new variable named newValue? How do I add this into the loop?

Do I need to make a second while loop or just add it to the first? What is newValue and do I need to declare it as a variable somewhere first?

let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0

repeat {
  counter += 1
} while counter < 1

// Enter your code below

1 Answer

Steven Parker
Steven Parker
217,602 Points

You don't actually need a new variable. When the instructions say "...where newValue is the value retrieved from the array", they mean you could refer to "numbers" and use the "counter" as an index to select a specific item from it.

But you may want to revise how the loop works so it will repeat the correct number of times. Task 1 included this hint: "You can get that number by using the count property"