Skip to content

Commit 588acec

Browse files
committed
🎨 go-05
1 parent ddf7f29 commit 588acec

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
<a href="https://github.com/java-aodeng/golang-examples/blob/master/go-04/1.md">第04章 运算符</a> :<a href="https://t.zsxq.com/qvvzZb2">星球链接</a>
1010

11+
<a href="https://github.com/java-aodeng/golang-examples/blob/master/go-05/1.md"> 第05章 条件和循环</a> :<a href="https://t.zsxq.com/qvvzZb2">星球链接</a>
12+
1113
## golang星球学习基地
1214
![](https://i.loli.net/2019/06/13/5d01b9fbec81470229.png)
1315

14-
第05章 条件和循环 :<a href="https://t.zsxq.com/qvvzZb2">星球链接</a>
15-
1616
第06章 数组和切片 :<a href="https://t.zsxq.com/qvvzZb2">星球链接</a>
1717

1818
第07章 Map 声明、元素访问及遍历 :<a href="https://t.zsxq.com/qvvzZb2">星球链接</a>

go-05/1.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,32 @@ func TestCondition(t *testing.T) {
4747
- 条件表达式不限制为常量或者整数
4848
- 单个case中,可以出现多个结果选项,使用逗号分隔
4949
- 与c语言等规则相反,go语言不需要用break来确定退出一个case
50-
- 可以不设定switch之后的条件表达式,在此种情况下,整个switch结构与多个if else 的逻辑作用相同
50+
- 可以不设定switch之后的条件表达式,在此种情况下,整个switch结构与多个if else 的逻辑作用相同
51+
52+
```
53+
func TestSwitch(t *testing.T) {
54+
for i:=0;i<5 ;i++ {
55+
switch i {
56+
case 0,2:
57+
t.Log("111111")
58+
case 1,3:
59+
t.Log("222222")
60+
default:
61+
t.Log("000000")
62+
}
63+
}
64+
}
65+
66+
func TestSwitch2(t *testing.T) {
67+
for i:=0;i<5 ;i++ {
68+
switch {
69+
case i%2==0:
70+
t.Log("111111%")
71+
case i%2==1:
72+
t.Log("222222%")
73+
default:
74+
t.Log("000000")
75+
}
76+
}
77+
}
78+
```

go-05/loop_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,27 @@ func TestCondition(t *testing.T) {
1919
}
2020

2121
func TestSwitch(t *testing.T) {
22+
for i:=0;i<5 ;i++ {
23+
switch i {
24+
case 0,2:
25+
t.Log("111111")
26+
case 1,3:
27+
t.Log("222222")
28+
default:
29+
t.Log("000000")
30+
}
31+
}
32+
}
2233

34+
func TestSwitch2(t *testing.T) {
35+
for i:=0;i<5 ;i++ {
36+
switch {
37+
case i%2==0:
38+
t.Log("111111%")
39+
case i%2==1:
40+
t.Log("222222%")
41+
default:
42+
t.Log("000000")
43+
}
44+
}
2345
}

0 commit comments

Comments
 (0)