switch caseNum { case0: print("Your case number is \(caseNum)") case1: print("Your case number is \(caseNum)") case2: print("Your case number is \(caseNum)") default: print("Out of case!") }
也可以在case中設置一個範圍來,只要在範圍中的都屬於那個case。
1 2 3 4 5 6 7 8 9 10 11 12 13
let caseNumNum =6
switch caseNumNum { case0...3: print("Your case number is \(caseNumNum)") case4...5: print("Your case number is \(caseNumNum)") case5...7: print("Your case number is \(caseNumNum)") default: print("Out of case!") }