From dd8d5e6b7262f525af5929f07abd3f772e900d87 Mon Sep 17 00:00:00 2001 From: mollusk Date: Thu, 24 Aug 2017 06:32:54 -0700 Subject: [PATCH] Derek Bana Tutorials: Arrays --- golearn/derek_banas_tutorial/Arrays/main.go | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 golearn/derek_banas_tutorial/Arrays/main.go diff --git a/golearn/derek_banas_tutorial/Arrays/main.go b/golearn/derek_banas_tutorial/Arrays/main.go new file mode 100644 index 0000000..81e0e00 --- /dev/null +++ b/golearn/derek_banas_tutorial/Arrays/main.go @@ -0,0 +1,33 @@ +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) + } + +}