This post originated from an RSS feed registered with .NET Buzz
by Jeff Key.
Original Post: Fun with "for"
Feed Title: Jeff Key
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/jkey/Rss.aspx
Feed Description: Topics revolve around .NET and the Windows platform.
Section 15.8.3 of the C# spec states that the “iterator” portion of the “for” statement “consists of a list of statement-expressions separated by commas”, not simply “Expression statement(s) to increment or decrement the loop counters”, as the MSDN docs proclaim. I mention this because I don't have a C background (although I did read a great primer in '96) and it's fun to be able to whip out something like the following every once in a while:
for
(int i = 0; i < shares.Length; shares[i] = (string)lstShares.SelectedItems[i++]);
True, it's the same as the more legitimate:
for (int i = 0; i < shares.Length;) shares[i] = (string)lstShares.SelectedItems[i++];
But when I do it the first way, I feel like I'm stickin' it to The Man. I don't know why, and that's probably a good thing. (Disclaimer: I don't actually do this “on the job“ since it's not visually parsed easily.)