for loops MDN code example
Example 1: forloop in js
for(i = 0; i < x; ++i){
//Loop, x can be replaced with any integer;
}
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;
}
}