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 while statement 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 "while statement error" Watch "while statement error" New topic
Author

while statement error

Sachin Kapoor
Greenhorn

Joined: Jul 01, 2007
Posts: 19
The question is which line is first to cause an error?

1 class Char
2 {
3 public static void main(String arg[])
4 {
5 while(false)
6 {
7 System.out.println("Hello");
8 }
9 while(false)
10 {
11 }
12 do;
13 while(false);
14 do
15 {
16 ;
17 }
18 while(false);
19 }
20 }

Choices are
1. Line no. 5
2. Line no. 9
3. Line no. 12
4. Line no. 16

Answer is Choice 1 is correct. It will give you error for unreached statement. All other statements are valid.

Does anyone know why exactly does line 5 give an error? If there is some code inside a while(false) loop, does it always give an error?
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Yes, all these are unreacheable code, if there is really code in between the brackets does not matter:



Yours,
Bu.


all events occur in real time
raghu nagabandi
Ranch Hand

Joined: Aug 14, 2007
Posts: 35
it always give compile time error
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: while statement error
 
Similar Threads
labels, breaks, and continue questions
unreachable statement again
unreachable statement
statement not reached error in while() loop
statement not reachable??