Loops

There are three basic forms of repetitive structures: while loops, do/while loops, and for loops. The general form of a while loop can be seen by the following example:
int i = 1;
while (i < 5) {
   System.out.print("i ="+ i);
   i++;
}

An example of the do/while loop:

int i = 1;
do {
   System.out.print("i ="+ i);
   i++;
} while (i < 5)

The difference between the while loop and the do/while loop is that the test for the while loop is executed at the beginning of the loop in contrast to the test for the do/while loop which is executed at the bottom of the loop. Because of this difference, the statements in a do/while loop will be executed at least once.

Updated 30 January 2000.