- One for loop within another for Loop is called nested for Loop
Nested Loop Execution :
for ( i =0 ; i<2 ; i++ )
for ( j =0 ;j<2 ; j++ )
{
printf ( "%d%d" , i , j )
}Steps :
| Step No | What happens ? | Line |
| 1 | i = 0 | 1 |
| 2 | i < 2 True Condition | 1 |
| 3 | Enter into Inner for Loop | 2 |
| 4 | Again j = 0 True | 2 |
| 5 | j < 2 True Condition | 2 |
| 6 | Execute Line 4 | 4 |
| 7 | But Inner for Loop has not completed yet , Control Goes to line no : 2 again | 2 |
| 8 | Execute : j ++ | 2 |
| 9 | Now j = 1 | 2 |
| 10 | Check j < 2 | 2 |
| 11 | True Condition Execute Line 4 | 4 |
| 12 | Execute : j ++ | 2 |
| 13 | Now j = 2 | 2 |
| 15 | Check j < 2 | 2 |
| 16 | False Condition | 2 |
| ************ At this Stage the Inner for Loop Completely Executed . | ||
| 17 | Execute i ++ | 1 |
| 18 | Now i = 1 Check Condition i < 2 | 1 |
| 19 | True Condition Goto Inner for Loop Similar to STEP 3 in this Table . | |
| 20 | Execute All Remaining Steps |

3:01 PM
Admin
Posted in:
0 comments:
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