Nested While loop?

Hello.

Can anyone explain me, how nested while loops works ?
Are the same things like in "for loop" ?

thanks a lot.
i know the syntax , but am looking for explain that how nested work ?
Well, a loop can be thought of like this:

1
2
3
    while (condition) {
        do_something
    }

where "do_something" can be any code you like, usually with some way of exiting the loop. Either change the value tested in "condition" or just use a "break" statement to escape from the loop.

A nested loop is exactly the same, except that some or all of "do_something" is itself a loop.
okay , my problem was in variable declaration , i declarate the variable that i used on inner loop , outside of the loop
thus:
1
2
3
4
5
6
7
8
9
10
11
12
int a=0;
int b=0;
		
while (a < 10){
a++;
	
while (b<10)
{
 b++;
		 
}
}
1
2
3
4
5
6
7
8
9
10
11
12
Instead : 
int a=0;
		
while (a < 10){
a++;
int b=0;
while (b<10)
{
 b++;
		 
}
}

, so the problem is showed in my program .
For that i asked to you to explaining me these things(where to declarate variable ,etc ) .
Last edited on
For that i asked to you to explaining me these things(where to declarate variable ,etc ) .


That one's fairly simple. Variables should be declared/defined as close as possible to their first use. I'm not sure what "etc" encompasses.
Topic archived. No new replies allowed.