help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: behavior of n++


From: Douglas Eck
Subject: Re: behavior of n++
Date: Thu, 12 Sep 2002 09:09:12 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1b) Gecko/20020722

Heber Farnsworth wrote:
There is probably some reason for the following behavior but I can't figure out what it might be.

$ octave -q
octave:1> n = 0
n = 0
octave:2> n++
ans = 0
octave:3> n++
ans = 1

I was expecting that if I set n=0 then n++ would be 1. Why is this not true?

Heber



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------


1 ruchetta ~>octave
octave:1> n=0
n = 0
octave:2> n++
ans = 0
octave:3> n
n = 1
octave:7> n=0
n = 0
octave:8> ++n
n = 1

The return value of post-increment is the value before
the incrementation. The return value of pre-increment
is the value after. This seems reasonable enought.
In either case, the variable is incremented... notice the value of n.

Cheers,
Doug

--
Dr. Douglas Eck, http://www.idsia.ch/~doug
Istituto Dalle Molle di Studi sull'Intelligenza Artificiale (IDSIA)
Neural Networks, Rhythm Perception and Production, Dynamical Systems



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]