Java Reference
In-Depth Information
Missing Pieces
Some interesting for loop variations are created by leaving pieces of the loop definition
empty. In Java, it is possible for any or all of the initialization, condition, or iteration por-
tions of the for loop to be blank. For example, consider the following program:
Here, the iteration expression of the for is empty. Instead, the loop control variable i is
incremented inside the body of the loop. This means that each time the loop repeats, i is
tested to see whether it equals 10, but no further action takes place. Of course, since i is still
incremented within the body of the loop, the loop runs normally, displaying the following
output:
Search WWH ::




Custom Search