Similar to the while loop is the do/while loop, which executes at least once and tests a conditional expression at the end of the loop to determine whether to continue iterating.

In the example below, we first make one pass through the loop, raking leaves. After executing the loop once, we count the remaining leaves on the lawn to determine if we need to continue raking and bagging.

In addition to completing normally, when the loop expression evaluates to false, a while loop can exit early. A loop will exit early if it encounters one of the following statements: break, goto, return or throw.

A break statement causes an early exit of the loop and execution to continue with the first statement after the loop.