Sunday, December 20, 2024

Nested for Loop in C | Nested for Loop Execution

Nested for Loop in C
  • 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 NoWhat happens ?
Line
1 i = 01
2i < 2 True Condition1
3Enter into Inner for Loop2
4Again j = 0 True 2
5j < 2 True Condition2
6Execute Line 44
7But Inner for Loop has not completed yet , Control Goes to line no : 2 again 2
8Execute : j ++ 2
9Now j = 1 2
10Check j < 2 2
11True Condition Execute Line 44
12Execute : j ++ 2
13Now j = 2 2
15Check j < 2 2
16False Condition2

************ At this Stage the Inner for Loop Completely Executed .
17Execute i ++ 1
18Now i = 1 Check Condition          i < 2 1
19True Condition Goto Inner for Loop Similar to STEP 3 in this Table .
20Execute All Remaining Steps

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

Copyright Notice | Link Exchange | Privacy Policy |Contact Us

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls