Hi Abhijit,
The For statement loop is used when you know how many times you want to execute a statement or a list of statements. For this reason, the For loop is known as a definite loop. The syntax of For loops is a bit more complex, though for loops are often more convenient than While loops. The For loop syntax is as follows:
for (initialization; condition; increment)
{
code to be executed;
}
The For statement takes three expressions inside its parentheses, separated by semi-colons. When the For loop executes, the following occurs:
1. The initializing expression is executed. This expression usually initializes one or more loop counters, but the syntax allows an expression of any degree of complexity.
2. The condition expression is evaluated. If the value of condition is true, the loop statements execute. If the value of condition is false, the For loop terminates.
3. The update expression increment executes.
4. The statements execute, and control returns to step 2.
Mar 17, 2010