Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

RE: RE(2): Flipper (Maintainability vs. personal style?)

by turnstep (Parson)
on May 21, 2000 at 20:41 UTC ( [id://14042]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://14042]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-16 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found