wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Question about do-while loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about do-while loop" Watch "Question about do-while loop" New topic
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: 65
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
 
wood burning stoves
 
subject: Question about do-while loop
 
Similar Threads
Using compareTo in a Loop
A question on WindowEvent
Do anyone got these errors whiel compiling the code in page 148-149 in head First java??
cannot find symbol?......wats happening???
static import of enums