title: Identifying last loop when using for each
body: <p>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.</p>
  
  <pre><code>  list = ['A','B','C']
    list.each{|i|
      puts "Looping: "+i # if not last loop iteration
      puts "Last one: "+i # if last loop iteration
    }
  </code></pre>
  
  <p>The output desired is equivalent to:</p>
  
  <pre><code>  Looping: 'A'
    Looping: 'B'
    Last one: 'C'
  </code></pre>
  
  <p>The obvious workaround is to migrate the code to a for loop using <code>'for i in 1..list.length'</code>, but the for each solution feels more graceful. What is the most graceful way to code a special case during a loop? Can it be done with foreach?</p>