| Author |
Question about do-while loop
|
Milton Ochoa
Ranch Hand
Joined: Oct 23, 2007
Posts: 336
|
|
This is pretty �Why cannot find the 'a' symbol (variable)? ---------------------------------- Test10.java:14: cannot find symbol symbol : variable a location: class Test10 }while(a == 0); ^ 1 error -------
|
 |
praveen Shangunathan
Ranch Hand
Joined: Sep 06, 2005
Posts: 64
|
|
You will have to declare 'a' before the do . for eg., int a; do{ a = 0; System.out.println(a); }while(a == 0);
|
 |
Petrus Pelser
Ranch Hand
Joined: Feb 20, 2006
Posts: 132
|
|
|
It's called variable scope. If you declare a variable inside a block, i.e inside braces {}, it will only be visible inside that block. In a do..while, or any other loop construct for that matter, the condition statement is clearly not inside the block and can thus not see any variables declared in that block.
|
 |
Milton Ochoa
Ranch Hand
Joined: Oct 23, 2007
Posts: 336
|
|
Thank you Mr. Petrus
|
 |
 |
|
|
subject: Question about do-while loop
|
|
|