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.
This problem can be solved in an elegant way using pattern matching in a functional programming language such as F#:
let rec printList (ls:string list) = match ls with | [last] -> "Last " + last | head::rest -> "Looping " + head + "\n" + printList (rest) | [] -> ""