Hi all,
I'm still new to all this... I am having a bit of difficulty
understanding something
about nested for loops. In the below program I have 2 cout statements
in the inside for loop. The cout <<"Hello "; runs 20 times, as
expected, but why does the cout<<"World "; only run 5 times when it
appears that it is also part of the inside loop. It seems that the
cout<<"World "; is obeying the laws of the outside for loop, not the
inside for loop. I tried adding a 3rd and 4th cout statement in the
inside loop, and they also ran 5 times, so would appear to be part of
the outside loop as well... Can someone shed some light as to why
this
is? I hope my question is clear.
#include <iostream>
using namespace std;
int main()
{
for (int counter = 0; counter < 5; counter++)
{ for (int inside = 0; inside < 10; inside++)
cout <<"Hello ";
cout <<"World: ";
}
}