• Post Reply Bookmark Topic Watch Topic
  • New Topic

unreachable code

 
Mike Ngo
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know why line 2 is OK?

1) int x = 0;
2) if (false) { x=1; } // OK
3) while (false) { x=2; } // error - unreachable code
 
Henry Wong
author
Sheriff
Posts: 22622
111
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is actually mentioned in the specification. The reason it is okay is to allow for conditional code... like ...



Henry
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!