Re: Funny loop with post-increment.

silky <[email protected]> Tue, 19 Feb 2008 19:44:20 +1100
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <[email protected]>
On Feb 19, 2008 7:33 PM, Brady Kelly <[email protected]> wrote:
> > Don't forget that this is a POST-increment. The return value of i++ is
> > the
> > original value of i, before it was incremented.
> >
> > -Chris
>
> I think we all know how post-increment works.  The question was why was i
> _still_ zero on the second loop iteration, after it should have been
> post-incremented.

it doesn't matter how many iterations; the value of anything that is
assigned as a postincrement (a = n++) is always equal to n. so that's
how it's defined in the spec and this is a side-effect of that
implementation. the thing to note is that the n++ is resolved directly
after that, before the statement itself has completed (i.e. the
function f(n++, n) results in differing values for the two params).

it's a specific result of the definition of the post-increment operation.

 --
http://lets.coozi.com.au/

A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com