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

getting confused in getting Sum of each value in array . help me out with solution . Does item needed to added with 1 ?

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

while counter < item { counter += 1

}

loops.swift
// Enter your code below

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

while counter < item {
   counter += 1


}

    // Enter your code below

1 Answer

Rickey Paape
Rickey Paape
23,989 Points

I believe the issue is the use of the item constant.

Just use numbers.count when you declare the while loop

while counter > numbers.count {
   counter += 1
}