This week's book giveaway is in the
Agile and other Processes
forum.
We're giving away four copies of
The Mikado Method
and have Ola Ellnestam and Daniel Brolund on-line!
See
this thread
for details.
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
while statement error
Sachin Kapoor
Greenhorn
Joined: Jul 01, 2007
Posts: 19
posted
Aug 28, 2007 11:14:00
0
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
posted
Aug 28, 2007 11:35:00
0
Yes, all these are unreacheable code, if there is really code in between the brackets does not matter:
while(false) [B];[/B] while(false) {} while(false){ System.out.println(5); }
Yours,
Bu.
all events occur in real time
raghu nagabandi
Ranch Hand
Joined: Aug 14, 2007
Posts: 35
posted
Aug 28, 2007 14:43:00
0
it always give compile time error
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: while statement error
Similar Threads
unreachable statement
labels, breaks, and continue questions
statement not reachable??
unreachable statement again
statement not reached error in while() loop
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter