title: Unreachable statement error using while loop in java
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9302133/why-is-this-code-giving-an-unreachable-statement-error">Why is this code giving an “Unreachable Statement” error?</a>  </p>
  </blockquote>
  
  
  
  <p>This seems very easy question, I found this question in one book. If anyone help me to figure out why I'm getting error. </p>
  
  <pre><code>    do {
          System.out.print("inside do");
      } while (false);
      while (false) { // error
          System.out.print("inside while");
      }
      System.out.print("outside");
  </code></pre>
  
  <p>I thought, and according to me, output should be <strong>inside dooutside</strong>. But, it is showing <strong>Compiler Error : Unreachable Statement</strong>. Then, I tried to figure out, why, it is showing <strong>Compilation error : Unreachable Statement*</strong> . So, I change the above code like this</p>
  
  <pre><code>  boolean i = false;  
    do {
          System.out.print("inside do");
      } while (false);
      while (i) { // ok
          System.out.print("inside while");
      }
      System.out.print("outside");
  </code></pre>
  
  <p>Now, it is showing expected output i.e. <strong>inside dooutside</strong> . So, my question is - what makes difference in first and second case ?
  Also, when I check </p>
  
  <pre><code>if(false){ 
    //something here
     }
  </code></pre>
  
  <p>Then, above code executes without any error.</p>