At 15:37 2007-03-10, len_kim wrote:
>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,
you sure you don't mean 50 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++)
the next for will execute ONE statement only... the cout << "Hello ";
if you'd wanted it to execute both statements you should enclose them in { }
>{ for (int inside = 0; inside < 10; inside++)
> cout <<"Hello ";
> cout <<"World: ";
>
>
>}
>
>}
>
>
>
>
>To unsubscribe, send a blank message to
><mailto:[EMAIL PROTECTED]>.
>Yahoo! Groups Links
>
>
>
Victor A. Wagner Jr. http://rudbek.com
The five most dangerous words in the English language:
"There oughta be a law"