for fo loop code example
Example 1: Iterate with JavaScript For Loops
var myArray = [];
for (var i = 1; i <= 5; i++){
myArray.push(i);
}
console.log(myArray) // console output [ 1, 2, 3, 4, 5 ]
Example 2: mdn for..of
function* fibonacci() { // a generator function
let [prev, curr] = [0, 1];
while (true) {
[prev, curr] = [curr, prev + curr];
yield curr;
}
}
for (const n of fibonacci()) {
console.log(n);
// truncate the sequence at 1000
if (n >= 1000) {
break;
}
}