Logo

Programming-Idioms

History of Idiom 143 > diff from v17 to v18

Edit summary for version 18 by programming-idioms.org:
Restored version 16

Version 17

2018-04-02, 20:34:43

Version 18

2018-04-02, 21:25:31

Idiom #143 Iterate alternatively over two lists

Iterate alternatively over the elements of the list items1 and items2. For each iteration, print the element.

Explain what happens if items1 and items2 have different size.

Idiom #143 Iterate alternatively over two lists

Iterate alternatively over the elements of the list items1 and items2. For each iteration, print the element.

Explain what happens if items1 and items2 have different size.

Extra Keywords
parallel
Extra Keywords
parallel
Code
items1.zip(items2){|pair| puts pair}
Code
items1.zip(items2){|pair| puts pair}
Comments bubble
There will be as much pairs as there are items in items1. items2 will be "padded" with nils or trimmed as needed.
Comments bubble
There will be as much pairs as there are items in titem1. items2 will be "padded" with nils or trimmed as needed.