DEV Community

Discussion on: doWhile vs While

Collapse
 
stokesm profile image
Matthew Stokes

For any case where you need the instructions within the loop to execute at least once, regardless of the while condition.

A common contrived example is continuously asking for valid user input. My condition to check if the input is valid would be within the while, however I need the request for input to execute at least once before checking the condition, so I use a do...while.

Collapse
 
samuelcrudge profile image
Sam

Thank you! makes sense. :)