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

  • Home
  • SEARCH
  • 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 6542273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:12:20+00:00 2026-05-25T11:12:20+00:00

While loking up dead code thread here dead code warning in eclipse I tried

  • 0

While loking up “dead code” thread here
dead code warning in eclipse

I tried the following simple java code:

public class Test2
{
    public static void main(String[] args)
    {
        int x = 0;        
        while(false)
        {                        
            x=4;
        }
    }
}  

which correctly throws a compile time error

C:\Documents and Settings\user\Desktop\Test2.java:7: unreachable
statement
        {                        
        ^ 1 error

I tweaked the code very slightly to this:

public class Test2
{
    public static void main(String[] args)
    {
        int x =0;        
        while(true)
        {                        
            x=4;
        }
    }
}    

and it compiles just fine.

Is there a reason, why this compiles fine?

logically both should cause an infiniteloop and should both cause compile time error.

Am I doing something wrong?

  • 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-05-25T11:12:20+00:00Added an answer on May 25, 2026 at 11:12 am

    logically both should cause an infiniteloop

    Not quite: while(false) never enters the loop.

    Also, the compiler doesn’t warn about infinite loops – you may actually want one:

    while(true) {
        // poll some queue for work
        // if work found do it
        // else sleep 1 second
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While looking in the code of the method: Integer.toHexString I found the following code
While looking at the System.Type class under the Code Definition Window, I cannot seem
While looking through the Java API source code I often see method parameters reassigned
While looking at a micro-optimization question that I asked yesterday ( here ), I
While looking at online code samples, I have sometimes come across an assignment of
My problem is very simple, yet I feel lost while looking at it ...
While looking through a 3rd party JavaScript API and example code I noticed the
Inspired by a thought while looking at the question " Correct HTTP status code
While looking at the code in petclinic, part of Spring 3.0 samples I noticed
while looking at Shrinkr 's source code (we all review other project's source code

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.