This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

while statement error

 
Sachin Kapoor
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, all these are unreacheable code, if there is really code in between the brackets does not matter:



Yours,
Bu.
 
raghu nagabandi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it always give compile time error
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic