ming yeow ming yeow - 1 year ago 74
Ruby Question

Finding out current index in EACH loop (Ruby)

Possible Duplicate:

Automatic counter in Ruby for each?

I want to find out the current index while i am in the each loop. how do i do so?


X.each do |p|
puts "current index..."

Answer Source
X.each_with_index do |item, index|
  puts "current_index: #{index}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download