File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question about do-while loop" Watch "Question about do-while loop" New topic

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)?

---------------------------------- 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;
a = 0;
}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
I agree. Here's the link:
subject: Question about do-while loop
It's not a secret anymore!