Finding out current index in EACH loop (Ruby)

Posted by ming yeow on Stack Overflow See other posts from Stack Overflow or by ming yeow
Published on 2010-05-17T02:15:45Z Indexed on 2010/05/17 2:20 UTC
Read the original article Hit count: 219

Filed under:
|

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

X=[1,2,3]

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

© Stack Overflow or respective owner

Related posts about ruby

Related posts about foreach