Re: Funny loop with post-increment.

Jon Skeet <[email protected]> Tue, 19 Feb 2008 08:53:04 +0000
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <[email protected]>
Ryan Heath wrote:
> On Feb 19, 2008 9:39 AM, Jon Skeet <[email protected]> wrote:
>> Which feature exactly?
>
> The feature that the returned value of i++ is i and not i+1.

Um, that's the definition of post-increment. If you want pre-increment,
use ++i. Sometimes you want post-increment behaviour, sometimes you want
pre-increment behaviour - but you need to know what they both do.

>> Now code like this should be avoided, certainly - but try prohibiting it
>> within the language spec! (The spec would be very, very tricky to get
>> right - and it might not even be possible.)
>
> Why is it not simply the obvious value? That could have been documented.

It *is* documented. Everything is working exactly as specified, and I
don't see anything wrong with how it's specified.

> Btw. Is the returned value of ++i, i or i+1?

The value of i after the increment.

Jon

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

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