Friday, 30 May 2014

Understanding of For loop

#include<stdio.h>
int main()
{
        int i;
        for(i=0;i<=5;i++)
              printf("Hello World");
         return 0;
}
Lets start with step by step and what will happen when condition is true:
Seq.No        Statement Flow                Explanation
01    Flow No 1 will be executed            i = 0
02    Flow No 2 will be executed            Condition Checking
03    Flow No 3 will be executed        True Condition and print Hello World
04    Flow No 4 will be executed              -
05    Flow No 5 will be executed            i = 1
06    Flow No 3 will be executed        True Condition and print Hello World
07    Flow No 4 will be executed              -
08    Flow No 5 will be executed            i = 2
09    Flow No 3 will be executed        True Condition and print Hello World
10    Flow No 4 will be executed              -
11    Flow No 5 will be executed            i = 3
12    Flow No 3 will be executed        True Condition and print Hello World
13    Flow No 4 will be executed              -
14    Flow No 5 will be executed            i = 4
15    Flow No 3 will be executed        True Condition and print Hello World
16    Flow No 4 will be executed              -
17    Flow No 5 will be executed            i = 5
18    Flow No 3 will be executed            False Condition

Therefore it gives five times Hello World . Ok Guys i think u will understand of whole scenario.

0 comments :

Post a Comment