Programming-Idioms

History of Idiom 163 > diff from v7 to v8

Edit summary for version 8 :
New Go implementation by user [programming-idioms.org]

Version 7

Version 8

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Imports
import "fmt"
Code
for i := 0; i+1 < len(list); i += 2 {
	fmt.Println(list[i], list[i+1])
}
Demo URL
https://play.golang.org/p/lh8J17IxE7w