Loops in JavaScript
Loops in JavaScript: Repeating with while, Counting with for.
Updated
- Repeating with while (Novice): A while loop repeats a block of code for as long as its condition stays true, which fits any job where you can't know in advance how many times it will take, as long as something inside the loop lets it end.
- Counting with for (Novice): A for loop puts its start, its condition and its step in one line, so counting up, counting down or counting by any step reads at a glance, and break and continue let you stop early or skip a pass.