Ok, so here we start with a variable called myArr, which holds an array of Number values:
var myArr = [2, 3, 4, 5, 6];.
The next variable is a number, holding a Number value of zero:
var total = 0;
In the for loop, we declare an index counter
var i = 0 on initialization of the loop, a condition during which to execute the logic inside the loop (
i < myArr.length), and final expression to call at the end of each iteration through the loop (
Each time the loop runs, which is once for each entry in the array
myArr, we are going to update the total by adding the value that is in the array at the index
i. Recall that
total += myArr[i] is shorthand for
total = total + myArr[i].
So the loop will initialize an index counter, run until the index counter is equal to the length of
myArr, and at the end of each iteration, the index counter will be incremented by one. Thus for each iteration of the loop,
myArr[i] is equal to the value in the array at the index
i. In the first iteration,
myArr[i] == myArr == 2. With each loop, this value is added to the total variable, giving you the total of all values in the array.
I hope that wasn’t too confusing! Best of luck!