http://qs321.pair.com?node_id=14042


in reply to RE(2): Flipper (Maintainability vs. personal style?)
in thread Flipper

> I guess my question is: why do you think I am throwing
> away a result which you only accomplish differently?
> "++" vs. "+ 1" -- they both add one to the value
> of $flip.

Um, no, they do not. Saying
$flip + 1;
does not change in any way the scalar referred to by $flip, while "++$flip" does. Simple as that.

===
What, fundamentally, is the difference between 
  $flip = ++$flip % 4
        and 
  $flip = ($flip + 1) % 4
===
The first changes the value of $flip twice, the second, only once. In the first one, the computer is saying:
  1. Increase the value of $flip by one
  2. Modulo 4 it
  3. Assign the result into $flip
versus:
  1. Compute the value of $flip + 1
  2. Modulo for that (temporary) value
  3. Assign the result into $flip

Replies are listed 'Best First'.
RE:(4) Flipper (++ instead of += 1)
by Russ (Deacon) on May 22, 2000 at 04:58 UTC
    turnstep said: Saying
    $flip + 1;
    does not change in any way the scalar referred to by $flip, while "++$flip" does.

    Yes, turnstep, of course the preincrement modifies $flip.

    The question at issue is, "Why do we care about modifying a variable twice?" Simple as that.

    Go back and read the post and respond to the actual issue, please.

    Russ