Logo

Programming-Idioms

History of Idiom 7 > diff from v79 to v80

Edit summary for version 80 by alllex:
[Kotlin] Shorter and less garbage

Version 79

2019-10-07, 08:54:26

Version 80

2019-10-09, 22:39:34

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.withIndex().forEach { (i, x) -> 
  print("i=$i x=$x") 
}
Code
items.forEachIndexed { i, x -> 
  print("i=$i x=$x") 
}