|
|
See also here.
The while statement executes an Expression and a Statement repeatedly until the value of the Expression is false.
WhileStatement:
while ( Expression )
Statement
Example:
x = 1;
while ( x < 10 ) {
print x
x += 2;
}
As a Nassi Shneidermann diagram:
The Expression must have type boolean, or a compile-time error occurs.
A while statement is executed by first evaluating the Expression. If evaluation of the Expression completes abruptly for some reason, the while statement completes abruptly for the same reason. Otherwise, execution continues by making a choice based on the resulting value:
If the value is true, then the contained Statement is executed. Then there is a choice:
If execution of the Statement completes normally, then the entire while statement is executed again, beginning by re-evaluating the Expression.
If the value of the Expression is false, no further action is taken and the while statement completes normally.
If the value of the Expression is false the first time it is evaluated, then the Statement is not executed.
|
|
Created by
unroff,
java2html &
& hp-tools.
© by csfac. All Rights Reserved (2010).
It is not allowed to print these pages on a CAST printer.
Last modified: 01/April/10 (17:16)