while keyword

Syntax

>>-while-(-Expression-)-Statement-><

Description
The while statement executes an Expression and a Statement repeatedly until the value of the Expression is false. If the Expression is not of type boolean, a compilation error occurs.

A while statement is executed by first evaluating the Expression:

Abrupt completion of the contained Statement is handled in the following manner:

Example
The following is an example of a while statement:

int a = 1;
int b;

/*
* Execute the body of the loop until the value of
* a is greater than 25.  The value of a + b is
* printed each time through the loop.
*/
while (a <=25) {
    b = a * 10;
    System.out.println(a + b);
    a++;
}

ngrelr.gif (548 bytes)
Syntax diagrams
Labeled statements
break keyword
continue keyword

Source: The Java Language Specification. Copyright (C) 1996 Sun Microsystems, Inc.