|
Go is similar: package main
import "fmt"
var vec = []string{"the", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog"}
func main() {
for i, s := range vec {
fmt.Printf("%d: %s\n", i, s)
}
}
Using `fmt.Println(i, ":", s)` inserts spaces on both sides of the colon, so the output is not quite right.I find Go's `range` syntax easier to read than D's `(i, s; vec)` -- although generator functions that work with `range` have unaesthetic return types. |
It's nice because it makes the syntax for arrays and ranges interchangeable, making for easy refactoring.