JS LOOPSChapter 3 · JS Collections & Loops
While Loops
A while loop repeats its block for as long as the condition is true, checking before every pass. Use it when you do not know in advance how many times to loop. Something inside the loop must change the condition, or it never ends. A do...while loop runs its block once before the first check.
Worked example
How it reads
- The condition is checked before each pass, so the loop may run zero times
fuel -= 3moves the loop toward its enddo...whilealways runs at least once

Cloud tip: If the runner stops your code for running too long, look for a while loop whose condition never becomes false.


