About the For Statement
Like while and do/while, the for statement is used to create an execution loop. A loop usually contains an initialization expression that sets the initial value of a counter, an expression that tests the counter value, and an incrementing expression that alters the counter. Using while, the initialization and incrementing expressions are not part of the basic statement syntax. Instead, they are separate statements. The for statement simply integrates these additional statements into a single composite statement.
See About the While statement.
See About the Do/While Statement.
For has the following format:
This is identical to the while statement:
For example, code that sums the square of all integers between 1 and 10 can be created using for as follows:
The for statement does not provide any functionality you cannot accomplish using while; it lets you create code that is a bit more structured. For this reason, you use the for statement most often to create program loops.