JS: for while do Loop
By Xah Lee. Date: . Last updated: .
for-loop
for (let i=0; i < 9; i++) { console.log(i); }
while-loop
let x = 0;
while (x !== 5) { console.log(x); x++;}
do-while Loop
let x = 0;
do { console.log(x); x++} while (x !== 5);
βcontinueβ, βbreakβ
continue
exit the current iteration in a loop.
break
exits the loop completely.
for (let i=0; i <= 5; i++) {
if (i===3) {continue;} console.log(i);
}
for (let i=0; i < 5; i++) {
console.log(i);
if (i===3) {break;}
}
JavaScript, Loop, Iteration