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 Please exaplin this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Please exaplin this code " Watch "Please exaplin this code " New topic
Author

Please exaplin this code

Akhilesh Yadav
Ranch Hand

Joined: Apr 04, 2006
Posts: 46
class Char
{
public static void main(String arg[])
{
while(false) //1
{
System.out.println("Hello");
}
while(false) //2
{
}
do;
while(false);
do
{
;
}
while(false);
}
}

when i run this programm it gives me error at first while //1 saying unreachable code becuase while is false
i chnaged it to true first while its working

same erroer for second while but when i changed second while to true its still showing unreachable code please can anyone Expalin me why ?
Anton Uwe
Ranch Hand

Joined: Jan 10, 2007
Posts: 122
Let's take a look at a simplier code example:

If you have "false" in //1, the code inside the braces (printing "Hello1") is unreachable. If you have "true" in //1, the code after the braces (printing "Hello2") is unreachable.
Giri Kanduri
Greenhorn

Joined: Jan 10, 2007
Posts: 2
class Char{
public static void main(String arg[]){
while(true) //1
{
System.out.println("Hello");
}
while(true) //2
{
}
}
}

In the above code it will not reach the second while loop bcz the first while loop is an infinite loop...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please exaplin this code