Logo

Programming-Idioms

History of Idiom 7 > diff from v96 to v97

Edit summary for version 97 by programming-idioms.org:
[Groovy] +DemoURL. Variable names i, x, items.

Version 96

2020-11-04, 11:51:07

Version 97

2020-11-05, 10:41:36

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
traverse traversal
Extra Keywords
traverse traversal
Code
['aaa', 'bbb', 'ccc'].eachWithIndex {
  element, index ->
  println "Item $index = $element"
}
Code
items.eachWithIndex {
  x, i -> println "Item $i = $x"
}
Comments bubble
iterate over a string list
Demo URL
https://groovyconsole.appspot.com/script/5084818014470144