使用 fallthrough 會強制執行后面的 case 陳述句,fallthrough 不會判斷下一條 case 的運算式結果是否為 true
實體
package main
import "fmt"
func main() {
switch {
case false:
fmt.Println("1、case 條件陳述句為 false")
fallthrough
case true:
fmt.Println("2、case 條件陳述句為 true")
fallthrough
case false:
fmt.Println("3、case 條件陳述句為 false")
fallthrough
case true:
fmt.Println("4、case 條件陳述句為 true")
case false:
fmt.Println("5、case 條件陳述句為 false")
fallthrough
default:
fmt.Println("6、默認 case")
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/18228.html
標籤:go語言
上一篇:求解?
