Application
Create new folder named src. In src folder, create new file named main.go as below:
package main
import "fmt"
func main() {
a := [5]int{2, 4, 6, 8, 10}
fmt.Println("Length : ", len(a))
fmt.Println(a)
fmt.Println("List of Elements")
for i := 0; i < len(a); i++ {
fmt.Printf("%d the element of a is %d\n", i, a[i])
}
fmt.Println("\nList of Elements")
for index, value := range a {
fmt.Printf("%d the element of a is %d\n", index, value)
}
}
Output
Open Terminal windows in Visual Studio Code and run command line: go run main.go
Length : 5
[2 4 6 8 10]
List of Elements
0 the element of a is 2
1 the element of a is 4
2 the element of a is 6
3 the element of a is 8
4 the element of a is 10
List of Elements
0 the element of a is 2
1 the element of a is 4
2 the element of a is 6
3 the element of a is 8
4 the element of a is 10