« Streaming Multiple SOAP Responses | Main | Iterating multiple soap responses with Yield Return »

Still more than 3 ways to loop it...

A discussion on looping in C# misses my favorite approach to looping, of course this only works if order of execution does not matter...

for (int i = foo.Length - 1; i >= 0; i--) {}

The big advantage here is that we are not going up to some unknown number that has to be stored on the side or accessed from a (potentially mutable) field. This saves one value on the register stack

It also works if you are trying to index the first occurance, although going forward and breaking out of the loop seems to work better in those cases.

21 Apr 2004 9:15 pm MDT: Edited to explain what I think is novel about it.


This page contains a single entry from the blog posted on April 22, 2004 9:09 AM.

The previous post in this blog was Streaming Multiple SOAP Responses.

The next post in this blog is Iterating multiple soap responses with Yield Return.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33