Java Reference
In-Depth Information
The output generated by the program is shown here:
In this example, count is the loop control variable. It is set to zero in the initialization por-
tion of the for . At the start of each iteration (including the first one), the conditional test
count < 5 is performed. If the outcome of this test is true, the println( ) statement is ex-
ecuted, and then the iteration portion of the loop is executed, which increases count by 1.
This process continues until the conditional test is false, at which point execution picks up
at the bottom of the loop. As a point of interest, in professionally written Java programs,
you will almost never see the iteration portion of the loop written as shown in the preceding
program. That is, you will seldom see statements like this:
The reason is that Java includes a special increment operator that performs this operation
more efficiently. The increment operator is ++ (that is, two plus signs back to back). The
increment operator increases its operand by one. By use of the increment operator, the pre-
ceding statement can be written like this:
Search WWH ::




Custom Search