package main
import "fmt"
func main() {
var i int = 10
switch true {
case i < 20:
fmt.Printf("%v is less than 20\n", i)
i = 100
fallthrough
case i < 19:
fmt.Printf("%v is less than 19\n", i)
fallthrough
case i < 18:
fmt.Printf("%v is less than 18\n", i)
fallthrough
case i > 50:
fmt.Printf("%v is greater than 50\n", i)
fallthrough
case i < 19:
fmt.Printf("%v is less than 19\n", i)
fallthrough
case i == 100:
fmt.Printf("%v is equal to 100\n", i)
fallthrough
case i < 17:
fmt.Printf("%v is less than 17\n", i)
}
}
输出:
10 is less than 20
100 is less than 19
100 is less than 18
100 is greater than 50
100 is less than 19
100 is equal to 100
100 is less than 17
这是预期的行为吗?
临摹微笑
慕森王
相关分类