You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
577 B
Go
32 lines
577 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
var myArray [5]int
|
|
var myArrayLiteral = [...]int{1, 2, 3, 3, 5}
|
|
|
|
func main() {
|
|
fmt.Println(myArray)
|
|
myArray[0] = 100
|
|
fmt.Println(myArray)
|
|
myArray[len(myArray)-1] = 1000
|
|
fmt.Println(myArray)
|
|
fmt.Println(myArrayLiteral)
|
|
|
|
// iterating through an array
|
|
for i := 0; i < len(myArrayLiteral); i++ {
|
|
fmt.Println(myArrayLiteral[i])
|
|
}
|
|
|
|
// iterate in reverse
|
|
for i := len(myArrayLiteral) - 1; i >= 0; i-- {
|
|
fmt.Println(myArrayLiteral[i])
|
|
}
|
|
|
|
// EVEN BETTER
|
|
for i, v := range myArrayLiteral {
|
|
fmt.Printf("index: %d, value: %d\n", i, v)
|
|
}
|
|
|
|
}
|