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.
Is this elegant enough? It assumes a non-empty list.
list[0,list.length-1].each{|i| puts "Looping:"+i # if not last loop iteration } puts "Last one:" + list[list.length-1]