I want to do something different with the last loop iteration when performing \'foreach\' on an object. I\'m using Ruby but the same goes for C#, Java etc.
You could do something like that (C#) :
string previous = null; foreach(string item in list) { if (previous != null) Console.WriteLine("Looping : {0}", previous); previous = item; } if (previous != null) Console.WriteLine("Last one : {0}", previous);