How do I know what iteration I'm in when using the Integer.times method?
23,164
Yes, just have your block accept an argument:
some_value.times{ |index| puts index }
#=> 0
#=> 1
#=> 2
#=> ...
or
some_value.times do |index|
puts index
end
#=> 0
#=> 1
#=> 2
#=> ...
Author by
EarlyPoster
Updated on November 17, 2020Comments
-
EarlyPoster over 3 years
Let's say I have
some_value = 23
I use the
Integer
'stimes
method to loop.Inside the iteration, is there an easy way, without keeping a counter, to see what iteration the loop is currently in?