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

Rabbie Wordie
Rabbie Wordie
1,441 Points

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
207,978 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"