The while keyword is used to create a loop construct. In a while loop, the expression in parentheses immediately following the keyword is evaluated, and if the boolean result is true, the statements appearing within the loop body are executed. If multiple statements make up the body of the loop, they must be enclosed with curly braces. Once the loop body has executed, control transfers back to the top of the loop where the test is performed again, and the execution of the loop body is repeated until the value of the expression evaluates to false.
The following example shows a typical while loop construct:
while ( i < 10 )
{
// statements here execute if above expression is true
.
.
.
}