Javascript - do...while Loops
Code Life
By Pierre Marsaa
Run First, Check Later
A while loop checks its condition before running the block. If the condition is false from the start, the block never runs:
↗️
Loading editor...
↶
↷
do...while does the opposite: it runs the block first, then checks the condition. The block is guaranteed to run at least once:
↗️
Loading editor...
↶
↷
Same condition, same value... but this time the message appears once. That's the only difference between the two loops.
Verify