Syntax
>>-do-Statement-while-(-Expression-)-;-><
Description
The do keyword executes a Statement and an Expression
repeatedly until the value of the Expression is false. A do
keyword always executes the contained Statement at least once. The Expression
must be type boolean; otherwise a compilation error occurs.
A do statement is executed by first executing the Statement; the
break and continue statement can be used to control execution of the loop from within the
statement. The Expression is then evaluated; if the value is true, then
the entire do statement is executed again. If the value is false, the
do statement completes normally.
Example
The following is an example of a do loop that prints a message every
time the loop iterates. The message would always print at least once, no matter what
our Expression is. In this case, the message will be printed five times.
int x = 1; do { System.out.println ("Print this message over and over again"); x++; } while (x <= 5);
Syntax diagrams
Java types
boolean keyword
break keyword
continue keyword
Source: The Java Language Specification. Copyright (C) 1996 Sun Microsystems, Inc.