MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Increment and AddTo

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64551] Increment and AddTo
  • From: dh <dh at metrohm.ch>
  • Date: Wed, 22 Feb 2006 05:58:34 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello,
can anybody explain the following behaviour:
$Version = 5.1 for Microsoft Windows (October 25, 2004)

i = 0;
v = {1, 2, 3};
v[[++i]] += 10;
v
i

gives
{1,11,3}
2

i has been incremented by 2!

i++ is even more interesting:
i = 1;
v = {1, 2, 3};
v[[i++]] += 10;
v
i

gives:
{1,11,3}
2

again i is incremented by 2, but for the sum v[[1]] is used and stored 
in v[[2]]

Further:
i = 0;
v = {1, 2, 3};
++v[[++i]] ;
v
i

gives:
{1,2,3}
2
Again i has been incremented by 2, but v has not been touched at all.

Daniel


  • Prev by Date: Re: question about Split[...]
  • Next by Date: Import Filemaker Pro 7 database into Mathematica 5.2
  • Previous by thread: Re: Combining ContourPlot and Plot
  • Next by thread: Re: Increment and AddTo