Do-while loop

The do-while statement creates a loop which executes at least once, and whose condition is checked after a loop iteration completes. The loop exits when the condition evaluates to 0.

Because do-while loops execute at least once, they are able to yield a value, unlike for and while loops which may not execute at all if the condition is initially false.

Do-while loops can be the target of break and continue statements.

Example

This example will repeatedly create a message popup until you input a number divisible by 10. Because the do-while loop is being used, the message box will always be shown at least once.

While this is a slightly contrived example, the above can be simplified slightly to take advantage of the fact that do-while loops can yield values: