Skip to content

Commit 98aec63

Browse files
committed
explain how for loop works
1 parent 1d37db2 commit 98aec63

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

looping/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ for (let i = 0; i < arrOfNums.length; i++) {
2626
arrOfNumsDoubled.push(arrOfNums[i] * 2)
2727
}
2828

29-
test.textContent = arrOfNumsDoubled;
29+
test.textContent = arrOfNumsDoubled;
30+
31+
// in the example above 'i' is being used as a counter. it refers to an index in an array. setting i=0 means the loop starts at index 0. as long as the index is less than the length of the array, the loop will continue to perform its inner operations. at each pass, the index number is incremented (i++). in the body of the loop we push new values (like those created in lines 15-19) to the new array.

0 commit comments

Comments
 (0)