|
|
@@ -171,15 +171,26 @@ switch 语句还可以被用于 type-switch(详见第 11.4 节)来判断某
|
|
|
请说出下面代码片段输出的结果:
|
|
|
|
|
|
```go
|
|
|
-k := 6
|
|
|
-switch k {
|
|
|
- case 4: fmt.Println("was <= 4"); fallthrough;
|
|
|
- case 5: fmt.Println("was <= 5"); fallthrough;
|
|
|
- case 6: fmt.Println("was <= 6"); fallthrough;
|
|
|
- case 7: fmt.Println("was <= 7"); fallthrough;
|
|
|
- case 8: fmt.Println("was <= 8"); fallthrough;
|
|
|
- default: fmt.Println("default case")
|
|
|
-}
|
|
|
+ k := 6
|
|
|
+ switch k {
|
|
|
+ case 4:
|
|
|
+ fmt.Println("was <= 4")
|
|
|
+ fallthrough
|
|
|
+ case 5:
|
|
|
+ fmt.Println("was <= 5")
|
|
|
+ fallthrough
|
|
|
+ case 6:
|
|
|
+ fmt.Println("was <= 6")
|
|
|
+ fallthrough
|
|
|
+ case 7:
|
|
|
+ fmt.Println("was <= 7")
|
|
|
+ fallthrough
|
|
|
+ case 8:
|
|
|
+ fmt.Println("was <= 8")
|
|
|
+ fallthrough
|
|
|
+ default:
|
|
|
+ fmt.Println("default case")
|
|
|
+ }
|
|
|
```
|
|
|
|
|
|
**练习 5.2:** [season.go](exercises/chapter_5/season.go):
|