34 lines
703 B
Go
34 lines
703 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
var favNums [5]float64 //define float64 array with 5 max index values
|
|
|
|
//Create index values
|
|
favNums[0] = 163
|
|
favNums[1] = 78557
|
|
favNums[2] = 691
|
|
favNums[3] = 3.141
|
|
favNums[4] = 1.618
|
|
|
|
//print the value of index 3
|
|
fmt.Println(favNums[3])
|
|
|
|
/*
|
|
Alternative way to define arrays by creating a variable
|
|
with a dynamic type,then giving the max size and all values
|
|
*/
|
|
|
|
favCats := [4]string{"Ringo", "Maynard", "Monochrome", "Myukie"}
|
|
|
|
/*Loop array and get range to print all array contents
|
|
You can replace the 'i' with '_' if you do not want to
|
|
print the index number of each value
|
|
*/
|
|
for i, value := range favCats {
|
|
fmt.Println(value, i)
|
|
}
|
|
|
|
}
|