Skip to content

Commit

Permalink
add: fallthrough keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatDiscovery committed Sep 19, 2024
1 parent 9398ea1 commit cb6b2ce
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 0 additions & 4 deletions test/basic/keyword/defer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,3 @@ func TestF(t *testing.T) {
println(f2())
println(f3())
}

func main() {

}
28 changes: 28 additions & 0 deletions test/basic/keyword/fallthrough_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package keyword

import (
"fmt"
"testing"
)

//fallthrough 的使用规则:
//fallthrough 只能用于 switch 语句中。
//它必须是某个 case 代码块的最后一条语句。
//使用 fallthrough 后,会无条件地执行下一个 case 代码块(即使下一个 case 的条件不匹配)

func TestFallThrough(t *testing.T) {
num := 2
switch num {
case 1:
fmt.Println("One")
case 2:
fmt.Println("Two")
fallthrough
case 3:
fmt.Println("Three")
case 4:
fmt.Println("Four")
default:
fmt.Println("Other")
}
}
4 changes: 0 additions & 4 deletions test/basic/keyword/make_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ func TestMake(t *testing.T) {
//hash := make(map[int]bool, 10)
//ch := make(chan int, 5)
}

func main() {

}

0 comments on commit cb6b2ce

Please sign in to comment.