forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample1.go
34 lines (27 loc) · 788 Bytes
/
example1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// Sample program to show how to declare and iterate over
// arrays of different types.
package main
import "fmt"
func main() {
// Declare an array of five strings that is initialized
// to its zero value.
var fruits [5]string
fruits[0] = "Apple"
fruits[1] = "Orange"
fruits[2] = "Banana"
fruits[3] = "Grape"
fruits[4] = "Plum"
// Iterate over the array of strings.
for i, fruit := range fruits {
fmt.Println(i, fruit)
}
// Declare an array of 4 integers that is initialized
// with some values.
numbers := [4]int{10, 20, 30, 40}
// Iterate over the array of numbers.
for i := 0; i < len(numbers); i++ {
fmt.Println(i, numbers[i])
}
}