dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Difference between i++ and i+=1

  1. #1
    Elvis...who tha f**k is Elvis? phreax's Avatar
    Join Date
    Feb 2001
    Posts
    1,836

    Smile

    I don't care what everybody says...there is a difference between the 2! The i++ doesn't update in the same way that the i+=1 does! If you for example use i++ and i+=1 about the same variable and in the same enterFrame, it's like it doesn't update as good, as with i+=1 and i+=1, the example is better if you add 5 the first place, and you just need to add 1 the other!

    ...any comments on these sick accusations?

  2. #2
    Senior Member
    Join Date
    May 2001
    Posts
    211
    Yes. I want proof! I like ++ (but I will easily change to +=1 if it is faser )

  3. #3
    Elvis...who tha f**k is Elvis? phreax's Avatar
    Join Date
    Feb 2001
    Posts
    1,836
    Well...the i++ works fine by itself, but when I try to mix the 2 expressions on the same variable, something weird happens!

    What I tried was this:

    in my hero MC I set the a var named _root.speed.

    on enterFrame it says _root.speed ++;

    everytime you press the right arrow it says _root.speed+=5;

    which means that when you press right, it actually goes up by 6 (5+1)...

    these numbers is set to affect my "powerbar" MC, which goes to a frame according to the speed. When I use the ++ it won't update, until after I release the key, but when I use += instead it updates all the time! ...I don't get it, but believe me there's a difference! Try it, and if it doesn't work, I will try posting some .swf's to show the difference!

  4. #4
    Senior Member
    Join Date
    Sep 2000
    Posts
    252
    I only use i++ in for loops
    eg
    for(x=0;x<10;x++)

    everything else i use i+=1

  5. #5
    Member
    Join Date
    Nov 2001
    Posts
    97
    there's something called "actionscript dictionary" that comes with flash. do yourself a favor and read it.

  6. #6
    w00t PrED32's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    529
    Okies.. Well this is actually a precedence question.

    i = i + 1; adds one to i.
    i+=1; adds one to i
    i++; adds one to i
    ++i; adds one to i

    Now the difference is if you try to do some kind of relation to the i.

    if you say go:
    var i = 5;
    trace(i++);
    trace(i)
    it will display : 5,6.
    and if you go

    var i = 5;
    trace(++i);
    trace(i);
    it will display: 6,6.

    The difference between i+=1, and i++/++i is simply that += is a shortcut, and ++i/i++ is actually its own operator

  7. #7
    Senior Member
    Join Date
    May 2001
    Posts
    211
    Thanks for clearing that up PrED.

  8. #8
    Elvis...who tha f**k is Elvis? phreax's Avatar
    Join Date
    Feb 2001
    Posts
    1,836
    Hey...I didn't even want to post anymore on this thread after reading the dic' explanation! The thing is, I never learned Flash like that, I just picked up what I could! So this is a perfect example of one of the holes you get, when you don't do the research! Sorry for taking your time

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center