Nested for loops

0 rasel ahmed · October 28, 2015
how does nested for loops work??

Post a Reply

Replies

Oldest  Newest  Rating
0 Parth Shah · October 28, 2015
The outer for loop will iterate the inner for loop the specified number of times and the inner for loop will execute the statement enclosed for the specified number of times
Say
for(i=0;i<5;i++)
    for(j=0;j<5;j++)
        printf("Hello!!!")

The output will be Hello!!! being printed 5(for j loop)*5(for i loop) i.e 25 times
0 Scott Walker · October 28, 2015
It runs the outside first then the inside
for(int i = 0; i < 5; i++)
{
   for(int j = 0; j < 5; j++)
   {
         cout << "j is now " << j << endl;
   }
}


So when i = 0, j will run 5 times.
when i = 1, j will run 5 times etc
0 rasel ahmed · October 30, 2015
thanks :D 
  • 1

C++

106,940 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator