Re: Funny loop with post-increment.

Per Bolmstedt <[email protected]> Tue, 19 Feb 2008 02:51:51 -0500
Newsgroups gmane.comp.windows.devel.dotnet.clr
Message-ID <LISTSERV%[email protected]>
On Tue, 19 Feb 2008 09:37:59 +0200, Brady Kelly <[email protected]>
wrote:

>            int i = 0;
>            while (i < 10)
>            {
>                i = i++;
>            }

>Why does this loop not exit?  On the first iteration, one would expect i ==
>0, and that 0 to be assigned to i, and then i incremented.  Then, on the

Depending on which "i" you are talking about, that's either true or false. =]

Maybe if you break it up into smaller operations and step through the code,
it would be more clear. Assign the result of i++ to a temporary variable
before you assign it back to i, etc.

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

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