Does ruby have anything where if I'm going through a do-while loop, or
a "3.times" loop or "for product in products" where there's a variable
that will tell me which iteration of the loop I'm on? Instead of
havign to declare my own counter = 0 and then increment it each time?
Seems like something Rails would have... I can't seem to find
anything on it.
Does ruby have anything where if I'm going through a do-while loop, or
a "3.times" loop or "for product in products" where there's a variable
that will tell me which iteration of the loop I'm on? Instead of
havign to declare my own counter = 0 and then increment it each time?
Seems like something Rails would have... I can't seem to find
anything on it.
Does ruby have anything where if I'm going through a do-while loop, or
a "3.times" loop or "for product in products" where there's a variable
that will tell me which iteration of the loop I'm on? Instead of
havign to declare my own counter = 0 and then increment it each time?
irb(main):001:0> 5.times {|i| puts i }
0
1
2
3
4
irb(main):002:0> ['one', 'two', 'three'].each_with_index {|i,e| puts i, e}
one
0
two
1
three
2
Don't know if "for product in products" has anything, but you could always do "products.each_with_index".