The do-while statement

Do / While VS While is a matter of when the condition is checked.

A while loop checks the condition, then executes the loop. A Do/While executes the loop and then checks the conditions.

For example, if the counterTwo variable was 10 or greater, then do/while loop would execute once, while your normal while loop would not execute the loop.


The do statement normally ensures your code gets executed at least once (expression evaluated at the end), whilst while evaluates at the start.


The do-while is guaranteed to run at least once. While the while loop may not run at all.