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 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?

loops.swift
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
231,184 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"