Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unreachable stmts

 
Sireesha Mullapudi
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Why 1& 4 are unreachable in the below code


Thanks,SCJP1.4


[HENRY: Added code tags. Fixed formatting.]
[ November 01, 2006: Message edited by: Henry Wong ]
 
prashanth kumar
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you havent used "CODE" tag,your code is not properly formatted..

Now i can only see line 1 properly which is

while(false);

Here ";" is an empty statement and since false is hardcoded in while loop,";" never gets executed under any circumstances..And hence the compiler error

All The Best
 
Sireesha Mullapudi
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is tthe code
 
Henry Wong
author
Marshal
Pie
Posts: 21514
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
line 1: Even though the while loop only has an "empty" statement, this statement is still considered unreachable because the while loop can never be true.

line 4: Even though the for loop only has an "empty" statement, this statement is still considered unreachable because the for loop can never be true.

line 3: The check for a do loop executes at the end of the loop. This means that a do loop will execute at least once, regardless of whether it is true or false. The body is always reachable.

line 2: Technically this if statement's body is unreachable -- but this is allowed in the specifications. The reason that this is allowed is to provided for conditional code -- like debugging code.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic