On Mon, 3 Mar 2008 23:10:09 +0900, Cory Cory <cg821105 / ohio.edu> wrote:
> I'm new to Ruby.  Is there such thing as a C++ style (and most others)
> for loop in Ruby?  What I mean by that is:
> 
> for( init, while-condition, increment ) { function-here }
> 
> I know I can do that with a while loop, but I enjoy the compactness of
> the above statement.  There are many times where Ruby's for-each loops
> just don't do the trick.

["foo", "bar", "baz"].each_with_index {|elem, i|
  puts "#{elem} #{i}"
}


    Kristian