174k views
3 votes
In a For loop the programmer must know the exact number of iterations the loop

must perform before writing the code.

True

False

User Klvs
by
6.6k points

1 Answer

2 votes

False

while in many cases a for loop might loop through a preset amount of data the number of iterations can also be stored in a dynamic variable

Preset

for(var i = 0; i < 50; i++){

console.log(i);

}

/*returns

1

2

3

4

5

etc it keeps going until 50

*/

Dynamic

// array size can be changed and still work

var arr = ["a","b","c"];

for(var x = 0; x< arr.length; x++){

console.log(arr[x])

}

/*returns

"a"

"b"

"c"

*/

User Igorc
by
7.7k points