package main
func main() {
n := 3
switch n := 1; n {
case 1:
fmt.Println("大拇指")
case 2:
fmt.Println("食指")
case 3:
fmt.Println("中指")
case 4:
fmt.Println("无名指")
case 5:
fmt.Println("小拇指")
default:
fmt.Ptrintln("无效数字")
}
switch n := 7; n {
case 1, 3, 5, 7:
fmt.Println("奇数")
case 2, 4, 6, 8:
fmt.Println("偶数")
default:
fmt.Println("error")
}
var age int = 20
switch {
case age > 0 && age < 18:
fmt.Println("未成年")
case age > 18 && age < 60:
fmt.Println("劳苦大众")
case age > 60:
fmt.Println("将至")
default:
fmt.Println("error")
}
s := "a"
switch {
case s == "a":
fmt.Println("a")
fallthrough
case s == "b":
fmt.Println("b")
fallthrough
case s == "c":
fmt.Println("c")
default:
fmt.Println("error")
}
goto+label跳出多层循环到我指定的标签
for i := 0; i < 10; i++ {
for j := 'a'; j < 'z'; j++ {
if j == 'd' {
goto label
}
fmt.Printf("%d,%cn", i, j)
}
}
label:
fmt.Println("over")
}