Pre-test Loop
With each iteration, the
program executes the loops block first and tests against a condition.
If the condition is
true, the loop continues and executes another iteration; if the condition is
false, the loop terminates.
With a post-test loop
the loop is executed at least once.
When the test takes place
at the bottom of the loop, then it is a post-test loop.
In each iteration of
post-test loop, the actions are executed first and then the condition is
checked.
If
the condition is true then the new iteration starts if not the loop terminates.
Initializing and Updating
Here, the action takes
place first and then the updating of action.
After the action is
updated the condition is tested.
The Comma Expression
The comma operator can
be used to link related and expression together.
It is a compound
expression containing two or more sub expressions separated with a comma and
evaluated from left to right.
The comma expression is
used in ‘for loop’ as given,
(Expression 1, expression 2, expression 3)
Example:
for(sum=0, i=1; i<20;
i++)
{
scanf(“%d”, &a);
sum +=a;
} //end for