File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes statement not reached error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "statement not reached error" Watch "statement not reached error" New topic
Author

statement not reached error

Ram Ganesh
Greenhorn

Joined: Feb 01, 2001
Posts: 11
class a{
public static void main(String args[]){
int i=4;
while(true)
System.out.println("abc"); // if this is commented it compiles properly
System.out.println("aa");
}
}
Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
Just as a comment, yes you are correct it only generates the
error when the statement cannot be reached.
Kevin Hou
Greenhorn

Joined: Jan 18, 2001
Posts: 27
while(true) is OK
whil(false) is compile error
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
i think that's because while statement is a block statement. unless you didn't provide {} for it , it can only execute one statement and if you have others it might not know what to do with it since braces were not provided.


Val SCJP <BR>going for SCJD
Anshuman Acharya
Ranch Hand

Joined: Jan 19, 2001
Posts: 144
just look at the code and see... how can the second statement be reached when the loop in the earlier statement can never end?
in fact if you'd written while (false) stat1;
it would have given the error for stat1
this holds true for loops generated thru... for(;true and for(;false too...
also, if (false) stat1 would compile! This provide the ability to conditionally compile the code...
Anshuman Acharya
Ranch Hand

Joined: Jan 19, 2001
Posts: 144
that's supposed to be
for (; false; ) and for(; true; )!
natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
Thanks a lot anshuman!!. I learnt a new concept.

Sun Certified Programmer for Java 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: statement not reached error