|
|
![]() | Syntax: while ( Expression ) Statement
|
![]() | Semantics: The expression must be of type boolean.
If it evaluates to false, the given statement is skipped,
Otherwise it is executed and afterwards the expression
is evaluated again. If it is still true, the statement
is executed again. This is continued until the
expression evaluates to false.
|
![]() | Following layout conforms to our coding standard:
while ( Expression ) { |
| HiLo.java |
guess = RitIo.getInteger("Your guess: ");
tries = 1;
while (guess != secretNumber) {
if (guess < secretNumber) {
System.out.println("Too small!");
} else {
// guess > secretNumber
System.out.println("Too large!");
}
guess = RitIo.getInteger("Your guess: ");
++tries;
}
|
|
| Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002 |