Loop Control in C : for loop
Syntax :
for(expression1 ; expression2 ; expression3)
{
body;
}
body;
}
expression1 | Initialization |
expression2 | Test Condition |
expression3 | Update Expression |
Execution :
- Expression1 is evaluated only once at the beginning .
- Expression2 is test Condition which is executed before executing body of the loop,if TEST CONDITION is true then only the Body of Loop is Executed.
- Expression3 is update Expression.It alters the value of Loop Control Variable
Example :
for ( i=0 ; i<100 ; i++ )
{
printf("Hi");
}
i | Subcript/Counter/Loop Control Variable |
i=0 | Initialization |
i<100 | Test Condition |
i++ | Update Expression |
Result :
- It will Print the "Hi" 100 times
- Refer to Topmost fig. Initially i = 0 initializes Loop Control Variable.
- It is checks with i<100 condition .
- Condition is found to be True. So it will Execute the Body of Loop.
- After execution , It will Execute Expression3 ( Update ) Now i = 1;
- Condition is again True so again body of loop is executed ,
- Similarly Body of loop is executed 100 times.
- At the end i = 100 & i<100 Condition violets So it bypasses the Loop body

Bookmark & Share
1 comments:
very very good.the method is mind blowing.
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email