The loop will print out Testing infinately. This happens because every time the outer for loop enters the inner for loop the iterator "i" is reset to 0, and when the inner loop exits it will be 5. The outer i++ then takes effect, making i=6. Since 6<10, the outer for loop executes again, starting the inner for loop. That for loop sets i=0, and the whole process starts over again.
Concept- Here the outer loop initialize the value of "i" with 0 only once, while inner for loop will initialize it every time.
Output- Infinite loop.
Reason- 1st iteration- --> outer--> i=0 inner--> it will iterate till i<5 i.e. at i=4, exit at i=5, 2nd iteration--> outer--> due to i++ , i=6. inner--> nowinner loop will again initializes i with 0 above process occurs again and so on.]
The loop will print out Testing infinately. This happens because every time the outer for loop enters the inner for loop the iterator "i" is reset to 0, and when the inner loop exits it will be 5. The outer i++ then takes effect, making i=6. Since 6<10, the outer for loop executes again, starting the inner for loop. That for loop sets i=0, and the whole process starts over again.
ReplyDeleteHi all,
ReplyDeleteConcept-
Here the outer loop initialize the value of "i" with 0 only once, while inner for loop will initialize it every time.
Output-
Infinite loop.
Reason-
1st iteration- -->
outer--> i=0
inner--> it will iterate till i<5 i.e. at i=4,
exit at i=5,
2nd iteration-->
outer--> due to i++ , i=6.
inner--> nowinner loop will again initializes i with 0 above process occurs again and so on.]
Thanks,
Tanzy.