Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Auto-increment frenzy

by belg4mit (Prior)
on Aug 27, 2003 at 00:39 UTC ( #286913=note: print w/replies, xml ) Need Help??


in reply to Auto-increment frenzy

Interesting, although it might have been more interesting had you given the expect results. I would expect
  1. 3
  2. 3
  3. 2

--
I'm not belgian but I play one on TV.

Replies are listed 'Best First'.
Re: Re: Auto-increment frenzy
by asarih (Hermit) on Aug 27, 2003 at 01:12 UTC
    As long as we are on the subject of expectations, I was expecting:
    1. 5 (the first $a++ assigns 2 to $a, the second $a++ assigns 3, and then $a = 3 + 2). Or the flying pigs out of my nose.
    2. 3
    3. 3
      the first $a++ assigns 2 to $a, the second $a++ assigns 3, and then $a = 3 + 2
      well, I would expect that the post increment actually postincrements:
      $a++ returns $a and increments after that; so the first $a++ returns 1 and now $a is 2, the second increment returns 2 and makes $a = 3
      so the addition returns 1 + 2 = 3.
      He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

      Chady | http://chady.net/

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-12-03 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?