Loop over array with indices


i have the recurring problem that i want to loop over an array with
each/collect/... but (as an afterthought) need the index of the current

for a while i have been using the "idiom":

array.zip((0..array.length).to_a).each {|a| ...}

but it really feels clunky, disfigures the source and feels like
something that would work really well in haskell, yet not in ruby :wink:
apart from looping with:

array.each_index {|i| a = array[i]; ...}

are there any nice, rubyesque ways of doing this?


BTW: what's the difference for an array of doing "array.each_index" as
opposed to "array.length.times"?