以下是用于在playground中执行Switch语句的代码.我执行了几个switch语句而没有使用default.我怀疑的是为什么它对某些人来说是可选的而且对于其他陈述是强制性的.谢谢提前!
let someNumber = 3.5
switch someNumber {
case 2 , 3 , 5 , 7 , 11 , 13 :
print("Prime numbers")
case 4 , 6 , 24 , 12 , 66 :
print("Normal numbers")
}
Run Code Online (Sandbox Code Playgroud)
计数器语句在不使用默认值的情
let yetAnotherPoint = (3,1)
switch yetAnotherPoint {
case let (x,y) where x == y :
print("(\(x),\(y)) is on the line x == y")
case let (x,y) where x == -y :
print("(\(x),\(y)) is on the line x == -y")
case let (x,y): …Run Code Online (Sandbox Code Playgroud)