一、區間運算符
閉區間運算符 a…b (包含a和b)
可以使用在for-in循環
for index in 1…5 {
//
}
半閉區間 a..<b (包含a 不包含b)
for index in 1..<3 {
//
}
二、控制轉移語句
Swift有四種控制轉移語句
continue
break
fallthrough
reyurn
這邊就用下fallthrough
Swift語言中的switch不會從商一個case分支落入到下一個case分支中。只要第一個匹配到的case分支完成了它需要執行的語句,整個switch代碼塊完成了它的執行。
如果需要C風格的落入(fallthrough)的特性,可以在每個需要該特性的case分支中使用fallthrough
let integerToDescribe = 5
var description = "The number \(integerToDescribe) is"
switch integerToDescribe {
case 2, 3, 4, 7, 11, 13, 17, 19:
description += "a prime number, and alse"
fallthrough
default:
description += "an integer."
}
print(description)