help-octave
[Top][All Lists]
Advanced

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

Re: behavior of n++


From: Dirk Eddelbuettel
Subject: Re: behavior of n++
Date: Wed, 11 Sep 2002 18:33:55 -0500


> 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?

Because the increment happens /after/ the print.  Try looking at n again now,
it will be 2.

Classic C++ semantics.  You probably wanted  ++n.

Dirk

-- 
According to the latest figures, 43% of all signatures are totally worthless.   



-------------------------------------------------------------
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]