Control Flow
While Loop
while repeats as long as its condition is true. Use it when you don't know in advance how many times to loop.
let countdown = 3;
while (countdown > 0) {
console.log(countdown);
countdown--;
}
console.log("Lift off!");Output
3 2 1 Lift off!
do...while
Runs the body at least once, then checks the condition.
let n = 10;
do {
console.log(n);
n++;
} while (n < 5);Output
10