each and each_with_index loop with range : As Iterator « Range « Ruby






each and each_with_index loop with range


(5..7).each {|x| print x }                 # Prints "567"
(5..7).each_with_index {|x,i| print x,i }  # Prints "506172"

 








Related examples in the same category

1.When a range is used as an iterator, each value in the sequence is returned.
2.each_slice loop with range
3.each_cons loop with range