The while statement
The while statement is used to repeatedly evaluate a boolean condition and execute a block as many times as the condition result is found to be true.
The condition, whose result type must be boolean, is evaluated and if the result is true, the block is executed. Control then transfers to the top of the loop and the condition is evaluated again. When the condition result is false, control is transferred to the next statement following the while statement.
The body of the loop must be a block; it must be inside curly braces.
Within the loop body, the break statement can be used to cause early termination of the loop by transferring control to the next statement after the loop body. The continue statement can be used to transfer control to the end of the body, after which the condition will be evaluated again and the loop body executed if the condition result is true. The return statement can be used to terminate both the loop and the action that contains it.
For more information, see
Defining loops.