For loop:
For loop is a powerful and versatile construct. Its general form is:
for (initialization;condition;iteration)
{
//body
}
If you have only one statement to repeat then you can do this without curly braces. The for loop operates as follows:
For loop is a powerful and versatile construct. Its general form is:
for (initialization;condition;iteration)
{
//body
}
If you have only one statement to repeat then you can do this without curly braces. The for loop operates as follows:
- When the loop starts first time, the initialization portion of the loop is executed. Generally, this is an expression that sets the value of the loop control variable, which acts as a counter that controls the loop. It is important to understand that the initialization expression is only executed once.
- Next, condition is evaluated. This must be a Boolean expression. If this expression is true then the body of the loop is executed. If it is false the loop terminates.
- Next, the iteration portion of the loop is executed. This is usually an expression that increments or decrements the loop control variables.
No comments:
Post a Comment