fork download
  1. package main
  2. import "fmt"
  3.  
  4. func main(){
  5. val := 6
  6.  
  7. fmt.Println("fallthrough:");
  8.  
  9. switch val {
  10. case 4: fmt.Println("was <= 4"); fallthrough;
  11. case 5: fmt.Println("was <= 5"); fallthrough;
  12. case 6: fmt.Println("was <= 6"); fallthrough;
  13. case 7: fmt.Println("was <= 7"); fallthrough;
  14. case 8: fmt.Println("was <= 8"); fallthrough;
  15. default: fmt.Println("default case")
  16. }
  17.  
  18. fmt.Println("NO fallthrough:");
  19.  
  20. switch val {
  21. case 4: fmt.Println("was <= 4");
  22. case 5: fmt.Println("was <= 5");
  23. case 6: fmt.Println("was <= 6");
  24. case 7: fmt.Println("was <= 7");
  25. case 8: fmt.Println("was <= 8");
  26. default: fmt.Println("default case")
  27. }
  28. }
Success #stdin #stdout 0s 789504KB
stdin
Standard input is empty
stdout
fallthrough:
was <= 6
was <= 7
was <= 8
default case
NO fallthrough:
was <= 6