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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:02:48+00:00 2026-05-23T06:02:48+00:00

How are they different? Here’s what I’m thinking, but I’m not sure…. If you

  • 0

How are they different? Here’s what I’m thinking, but I’m not sure….

If you use pre-incrementation, for example in a for loop with ++j, then you are basically saying: “Make a copy of the value of j for use in the loop, then increment j, then go through the statements in the loop with the copy of j.” If you are using post-incrementation in the same loop j++, then you are basically saying: “Make a copy of the value of j for use in the loop, then go through the statements in the loop with the copy of j, then increment j.”

The reason I’m unsure is because I’ve created a for loop that multiplies the value of j by 10 and then outputs the result for j=1 through j=12, using both post- and pre-incrementation. The human readable output is exactly the same with post- and pre-incrementation. I’m thinking, ‘How are the outputs exactly the same if there isn’t some kind of copy operation involved?’

So, I’m guessing the difference between pre- and post-incrementation truly becomes important, in php, when I use references (which act as pointers in php) rather than names for return values? This would be because copies of references aren’t made, so pre-incrementation would be: “Increment j, then go through the statements in the loop with the changed value of j, then increment j again…,” whereas post-incremetation would look like: “Use the value of j for the statements in the loop, then change the value of j, then go through the loop with the new value of j…”

  • 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-23T06:02:49+00:00Added an answer on May 23, 2026 at 6:02 am

    Pre- or post-incrementing do not magically delay things until later. It’s simply inline shorthand.

    enter image description here

    // pre-increment
    $var = 5;
    print(++$var); // increments first, then passes value (now 6) to print()
    
    // post-increment
    $var = 5;
    print($var++); // passes value (still 5) to print(), then increments
    

    Now let’s look at a loop.

    for ($i = 0; $i < 9; $i++) {
        print($i);
    }
    

    The last part of the loop declaration (the $i++) is simply the statement to execute after each time through the loop. It “passes” the value to nowhere, then increments it. $i isn’t used anywhere at that time. Later when the next statement is executed (print($i);), the value of $i has already increased.

    // add 1, then do nothing with $i
    for ($i = 0; $i < 9; ++$i) {}
    
    // do nothing with $i, then add 1
    for ($i = 0; $i < 9; $i++) {}
    

    Whichever way you do it, $i will be the same within the loop.


    If it helps, you can think of them as small routines that kind of do this:

    // ++$i
    {
        $i = $i + 1;
        return $i;
    }
    
    // $i++
    {
        return $i;
        $i = $i + 1;
    }
    

    As I reread your question, I think the confusion is more with how the loop works than how increment operators work. Keeping in mind that the increment is a straightforward, all-at-once operation, here’s how third expression in the loop works.

    // here's a basic loop
    for ($i = 0; $i < 9; $i++) {
        // do loop stuff
        print($i);
    }
    
    // this is exactly what happens
    for ($i = 0; $i < 9; ) {
        // do loop stuff
        print($i);
    
        $i++;
    }
    

    Just because that last line can be put in the loop declaration doesn’t give it any special powers. There are no references or anything used behind the scenes. The same $i variable is seen both inside and outside the loop. Every statement inside or outside the loop directly looks up the value of $i when necessary. That’s it. No funny business.

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

Sidebar

Related Questions

the guy that asks weird things, here, again I see that they use different
Are they different or they are used interchangeably? If they are Different, then what
I've looked at a number of different answers here, and they all seem to
After searching for many post here, I found no luck they are slightly different
I have followed different threads here and there related to deploying Orchard but for
I have multiple named scopes in my model. They have different names but same
I try to find out what basic different between Globalization and Localization? but not
I was looking at the answers from different questions here but cant get to
Is there a difference between this.form and document.forms (document[forms]) or, are they similar? Here
I want to compare two CSV files to see if they are different. I

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.