Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9029241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:12:13+00:00 2026-06-16T07:12:13+00:00

Possible Duplicate: Why is this code giving an Unreachable Statement error? This seems very

  • 0

Possible Duplicate:
Why is this code giving an “Unreachable Statement” error?

This seems very easy question, I found this question in one book. If anyone help me to figure out why I’m getting error.

    do {
        System.out.print("inside do");
    } while (false);
    while (false) { // error
        System.out.print("inside while");
    }
    System.out.print("outside");

I thought, and according to me, output should be inside dooutside. But, it is showing Compiler Error : Unreachable Statement. Then, I tried to figure out, why, it is showing Compilation error : Unreachable Statement* . So, I change the above code like this

  boolean i = false;  
  do {
        System.out.print("inside do");
    } while (false);
    while (i) { // ok
        System.out.print("inside while");
    }
    System.out.print("outside");

Now, it is showing expected output i.e. inside dooutside . So, my question is – what makes difference in first and second case ?
Also, when I check

if(false){ 
  //something here
   }

Then, above code executes without any error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:12:14+00:00Added an answer on June 16, 2026 at 7:12 am

    The main difference between the first two examples is that in the first case, the condition is a constant, whereas in the second it is not.

    For example, if you change boolean i = false; into final boolean i = false;, you will get the same compile error because i is now a constant.

    The rules for unreachable statements are defined in the JLS 14.21. In particular there is a special treatment for if to allow if(DEBUG) structures where DEBUG might be a constant.

    As for the do / while, the statement inside will be executed once so there is no problem.

    More details about the constants in this related post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: error using include_once with a php variable My code is like this:
Possible Duplicate: Two separate python lists acting as one This code creates a dictionary
Possible Duplicate: strtok giving Segmentation Fault Why do i get segfault using this code
Possible Duplicate: const and global This code will produce error in c++ // Foo.cpp
Possible Duplicate: Find url from string with php I found this code: but 2
Possible Duplicate: wordwrap a very long string My code <div style=width:40px;>adfdddddddddddddddddddd</div> This code should
Possible Duplicate: Why is this code invalid in C#? Conditional operator cannot cast implicitly?
Possible Duplicate: calling ASP function from javascript okay running this code : <script type=text/javascript>
Possible Duplicate: How to compare Dates in C# This code of mine: public static
Possible Duplicate: Python list append behavior Why does this code: x = [[]]*3 x[0].append('a')

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.