Search⌘ K

Solution Review: Filling Array with Loop Counter

Understand how to fill an array in Go using a loop counter by iterating over indices and assigning values. This lesson helps you master basic array manipulation and looping techniques in Go programming.

We'll cover the following...
Go (1.6.2)
package main
import "fmt"
func main() {
var arr [15]int
for i:=0; i < 15; i++ { // counter-controlled loop
arr[i] = i
}
fmt.Println(arr) // [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]
}

As you can see, in main at line 5 we declare an array arr with length 15. We set the length to 15 ...