package main
import "fmt"
func main() {
f2()
}
func f() {
day := 3
switch day {
case 1, 2, 3, 4, 5: //多条件判断,用分号分割即可
fmt.Printf("工作日")
case 6, 7:
fmt.Printf("休息日")
default:
fmt.Printf("非法输入")
}
}
func f1() {
score := 80
switch {
case score >= 90:
fmt.Printf("成绩优秀")
case score >= 80 && score <= 90: //可以使用逻辑表达式
fmt.Printf("好好学习")
case score <= 80 && score >= 60:
fmt.Printf("学习才是你唯一的出路")
default:
fmt.Printf("非法输入")
}
}
func f2() {
num := 100
switch num {
case 100:
fmt.Printf("100")
fallthrough
case 200:
fmt.Printf("200")
case 300:
fmt.Printf("300")
}
}
go语言switch相关
最新推荐文章于 2024-07-22 10:38:17 发布