in reply to post-increment/pre-increment blues

print ++$i + 1; # prints 2, increment and than add 1 print $i++ + 1; # prints 2, $i==1, take the old $i (1) and ad +d 1, the increment happens after the sum was calculated print $i + $i++; # prints 5, $i==2, the increments happens fir +st and we get 2+3 print ++$i + ++$i; # prints 10, $i==3, the pre increment is done + twice because it's precedens on '+' and than we get 5+5 print ++$i + $i++ + 1; # prints 14, $i==5, didn't figure out yet


Thanks.

Hotshot

Replies are listed 'Best First'.
Re: Re: post-increment/pre-increment blues
by hotshot (Prior) on Jun 18, 2002 at 09:56 UTC
    I see by the answer of fatvamp that we got different ansewr I guess ariels answer is the right one

    Thanks.

    Hotshot
Re: Re: post-increment/pre-increment blues
by Juerd (Abbot) on Jun 18, 2002 at 14:59 UTC

    print $i + $i++; # prints 5, $i==2, the increments happens first and we get 2+3

    3 + 2, not 2 + 3. Not that it matters, of course.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.