匹配多个值
switch 语句中的单个 case 可以匹配多个值。
let number = 3
switch number {
case 1, 2:
print("One or Two!")
case 3:
print("Three!")
case 4, 5, 6:
print("Four, Five or Six!")
default:
print("Not One, Two, Three, Four, Five or Six")
}
switch 语句中的单个 case 可以匹配多个值。
let number = 3
switch number {
case 1, 2:
print("One or Two!")
case 3:
print("Three!")
case 4, 5, 6:
print("Four, Five or Six!")
default:
print("Not One, Two, Three, Four, Five or Six")
}