Derek Bana Tutorials: Arrays
This commit is contained in:
parent
2e1fff90e8
commit
dd8d5e6b72
33
golearn/derek_banas_tutorial/Arrays/main.go
Normal file
33
golearn/derek_banas_tutorial/Arrays/main.go
Normal file
@ -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)
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user