Logo

Programming-Idioms

History of Idiom 7 > diff from v134 to v135

Edit summary for version 135 by programming-idioms.org:
[Ruby] Added Demo URL

Version 134

2022-09-02, 22:25:05

Version 135

2022-09-02, 22:27:03

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

Variables
i,x,items
Variables
i,x,items
Extra Keywords
indices traverse traversal
Extra Keywords
indices traverse traversal
Code
items.each_index{|i| puts "Item %d = %s" % [i, items[i]]}
Code
items.each_index{|i| puts "Item %d = %s" % [i, items[i]]}
Doc URL
https://ruby-doc.org/core-3.1.2/Array.html#method-i-each_index
Doc URL
https://ruby-doc.org/core-3.1.2/Array.html#method-i-each_index
Demo URL
https://replit.com/@ProgIdioms/BumpyLikableParallelalgorithm#main.rb