This language bar is your friend. Select your favorite languages!

Idiom #143 Iterate alternatively over two lists

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

(map (lambda (x)
       (display x)
     (foldr append '()
            (map list items1 items2)))
import std.range;
import std.algorithm.iteration;
import std.stdio;
roundRobin(items1, items2).each!writeln;
for i := 0; i < len(items1) || i < len(items2); i++ {
	if i < len(items1) {
	if i < len(items2) {
[items1, items2].transpose.each{|ar| 
  ar.each{|item| p item }

Do you know the best way to do this in your language ?
New implementation...

Idiom created by


Related idioms