This commit is contained in:
Mark McGranaghan 2012-09-16 12:15:01 -07:00
parent 02a0b20746
commit c6cf452643
5 changed files with 72 additions and 0 deletions

11
10-for.go Normal file
View File

@ -0,0 +1,11 @@
package main
import "fmt"
func main() {
i := 1
for i <= 10 {
fmt.Println(i)
i = i + 1
}
}

15
11-if.go Normal file
View File

@ -0,0 +1,15 @@
package main
import "fmt"
func main() {
i := 1
for i <= 10 {
if i % 2 == 0 {
fmt.Println("even")
} else {
fmt.Println("odd")
}
i = i + 1
}
}

10
12-arrays.go Normal file
View File

@ -0,0 +1,10 @@
package main
import "fmt"
func main() {
var x [5]int
x[4] = 100
fmt.Println(x)
fmt.Println(x[4])
}

18
13-sum.go Normal file
View File

@ -0,0 +1,18 @@
package main
import "fmt"
func main() {
var x [5]float64
x[0] = 98
x[1] = 93
x[2] = 77
x[3] = 82
x[4] = 83
var total float64 = 0
for i := 0; i < 5; i++ {
total += x[i]
}
fmt.Println(total / float64(len(x)))
}

18
14-range.go Normal file
View File

@ -0,0 +1,18 @@
package main
import "fmt"
func main() {
var x [5]float64
x[0] = 98
x[1] = 93
x[2] = 77
x[3] = 82
x[4] = 83
var total float64 = 0
for _, value := range x {
total += value
}
fmt.Println(total / float64(len(x)))
}