+ 3

Summing Elements in an Array Question

Why do we have to add x<myarr.Length as a condition in the for loop when trying to add up elements in an array? What purpose does it serve? Can someone also describe how this code works because my idea of it is pretty foggy?

21st Jun 2018, 6:36 AM
Evelyn
Evelyn - avatar
1 Answer
+ 1
To get element x of array you have to iterate over array. x<myArr.length means that you iterate to the last element of array.
21st Jun 2018, 6:50 AM
Lstiti