Monday, December 07, 2009

Easy loops

Loops are common in a lot of code. I made a few contructs in plain to make it even easier to do simple iterations in .net.
//do something 3 times

//count an integer from 3 to 8 (both included) and do some action for each value.
3.To(8).Do(i=>Console.WriteLine("The number is: " + i ))

I know this is sort of thing is common in languages like Ruby or F# but that's not gonna stop me from doing it in C# :)

The implementation can be found at


  1. Fun idea, but I'd have to say that a simple for loop is easy enough to read, and only a few extra keystrokes. In my opinion, if code could potentially be read by anyone else, I'd opt for simplicity and standard code.

  2. Hi Joe. I agree with you. Simplicity is the way to go. The question is how you define what is simple and how the programmers on your project define it. If you have introduced functional approaches like LINQ to your project I think this approach might be quite natural. I could be wrong. :)