Javascript - do...while Loops
📖 Read the lesson
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...
↶
▶️ Run
↷
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...
↶
▶️ Run
↷
Same condition, same value... but this time the message appears once. That's the only difference between the two loops.
Verify