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 9209717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:54:40+00:00 2026-06-18T00:54:40+00:00

I’m doing some research about Java and find this very confusing: for (int i

  • 0

I’m doing some research about Java and find this very confusing:

for (int i = 0; i < 10; i = i++) {
  System.err.print("hoo... ");
}

This is never ending loop!

Anybody has good explanation why such thing happens?

  • 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-18T00:54:41+00:00Added an answer on June 18, 2026 at 12:54 am
    for (int i = 0; i < 10; i = i++) {
    

    The above loop is essentially the same as: –

    for (int i = 0; i < 10; i = i) {
    

    the 3rd part of your for statement – i = i++, is evaluated as: –

    int oldValue = i; 
    i = i + 1;
    i = oldValue;  // 3rd Step 
    

    You need to remove the assignment from there, to make it work: –

    for (int i = 0; i < 10; i++) {
    

    (On OP request from Comments)

    Behaviour of x = 1; x = x++ + x++; : –

    As far as your issue as specified in the comment is concerned, the result of the following expression: –

    x = 1; 
    x = x++ + x++;
    

    is obtained as follows: –

    Let’s mark different parts of the second statement: –

    x = x++ + x++;
    R    A     B
    

    Now, first the RHS part (A + B) will be evaluated, and then the final result will be assignmed to x. So, let’s move ahead.

    First A is evaluated: –

    old1 = x;  // `old1 becomes 1`
    x = x + 1; // Increment `x`. `x becomes 2`
    //x = old1; // This will not be done. As the value has not been assigned back yet.
    

    Now, since the assignment of A to R is not done here, the 3rd step is not performed.

    Now, move to B evaluation: –

    old2 = x;  // old2 becomes 2. (Since `x` is 2, from the evaluation of `A`)
    x = x + 1; // increment `x`. `x becomes 3`.
    // x = old2; // This will again not be done here.
    

    Now, to get the value of x++ + x++, we need to do the last assignment that we left in the evaluation of A and B, because now is the value being assigned in x. For that, we need to replace: –

    A --> old1
    B --> old2   // The last assignment of both the evaluation. (A and B)
    
    /** See Break up `x = old1;` towards the end, to understand how it's equivalent to `A = old1; in case of `x = x++`, considering `x++ <==> A` in this case. **/
    

    So, x = x++ + x++, becomes: –

    x = old1 + old2;
      = 1 + 2;
      = 3;  // Hence the answer
    

    Break up of 3rd part of x = x++, to see how it works in x = x++ + x++ case: –

    Wonder why the replacement is done as A --> old1 and not x --> old1, as in case of x = x++.

    Take a deep look at x = x++ part, specially the last assignment: –

    x = oldValue;
    

    if you consider x++ to be A here, then the above assignment can be broken into these steps: –

    A = oldValue;
    x = A;
    

    Now, for the current problem, it is same as: –

    A = old1;
    B = old2;
    x = A + B;
    

    I hope that makes it clear.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

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.