1
2
3
4
5
6
7
8
9
10
11
12
| package main
import "fmt"
func main() {
number := 1
if number <10{
fmt.Println("number<10")
}else{
fmt.Println("number>10")
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| package main
import "fmt"
func main() {
number :=10
for i:=0;i<number;i++{
fmt.Println(i)
}
var t int
for ;;t++{
fmt.Println(t)
if t>5{
break //跳出当前循环;continue跳过当前这一次的循环,继续下一次的循环
}
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| package main
import "fmt"
func main() {
var arr = [3]int{1,2,3}
var slice = make([]int,3)
slice[0] =1
slice[1] =2
var m = map[int]int{1:1,2:2}
for k,v :=range arr{
fmt.Println(k,v)
}
for k,v :=range slice{
fmt.Println(k,v)
}
for k,v :=range m{
fmt.Println(k,v)
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
| package main
import "fmt"
func main() {
var n = 66
switch {
case n < 60:
fmt.Println("n<60")
case n > 60:
fmt.Println("n>60")
}
}
|