Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- switch i {
- case 0: // 空分支,只有当 i == 0 时才会进入分支
- case 1:
- f() // 当 i == 0 时函数不会被调用
- }
- switch i {
- case 0: fallthrough
- case 1:
- f() // 当 i == 0 时函数也会被调用
- }
- 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")
- }
Add Comment
Please, Sign In to add comment