Guest User

Untitled

a guest
Feb 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. switch i {
  2. case 0: // 空分支,只有当 i == 0 时才会进入分支
  3. case 1:
  4. f() // 当 i == 0 时函数不会被调用
  5. }
  6.  
  7. switch i {
  8. case 0: fallthrough
  9. case 1:
  10. f() // 当 i == 0 时函数也会被调用
  11. }
  12.  
  13. k := 6
  14. switch k {
  15. case 4: fmt.Println("was <= 4"); fallthrough;
  16. case 5: fmt.Println("was <= 5"); fallthrough;
  17. case 6: fmt.Println("was <= 6"); fallthrough;
  18. case 7: fmt.Println("was <= 7"); fallthrough;
  19. case 8: fmt.Println("was <= 8"); fallthrough;
  20. default: fmt.Println("default case")
  21. }
Add Comment
Please, Sign In to add comment