File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
unreachable statement
Parameswaran Thangavel
Ranch Hand
Joined: Mar 01, 2005
Posts: 485
posted
Apr 07, 2005 07:35:00
0
hi
why the compiler thrown unreachable error
how the true or false in while loop influence the unreachable statement at (1) and (2)
class
Test
{
public static void main (
String
args[])
{
int i=1;
do
while(false) //always true
System.out.println( "Ok" ) ;//unreachable statement (1)
while( i < 1 );
System.out.println("hai");
}
}
class Test
{
public static void main (String args[])
{
int i=1;
do
while(true) // true
System.out.println( "Ok" ) ;
while( i < 1 );
System.out.println("hai");//unreachable statement (2)
}
}
Anuj Troy
Ranch Hand
Joined: Apr 07, 2005
Posts: 30
posted
Apr 07, 2005 08:01:00
0
hi Parameswaran
the statement System.out.println("hai");//unreachable statement (2) is unreachable because the while loop is infinite.
you have written while(true)!! it will never get out of that loop..
thus the last line
"System.out.println("hai");//unreachable statement (2)"
is unreachable.
regards
anuj
SCJP 1.4, SCWCD 1.4
your eyes cannot see what your mind does not know
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: unreachable statement
Similar Threads
while loop
Compile time unreachability
More basic concepts
Unreachable statement
small doubt in while loop
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter