Logo

Programming-Idioms

History of Idiom 7 > diff from v59 to v60

Edit summary for version 60 by programming-idioms.org:
[Ruby] Variable name is x

Version 59

2017-04-17, 18:51:17

Version 60

2017-04-17, 18:51:49

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
items.each_with_index do |el, i| 
  puts "Item #{i} = #{el}"
end
Code
items.each_with_index do |x, i| 
  puts "Item #{i} = #{x}"
end
Comments bubble
See also the one-liner Ruby solution
Comments bubble
See also the one-liner Ruby solution