以數(shù)組舉例
//最近迷上了吃雞笋庄。
var nameArray = ["手槍","散彈槍","沖鋒槍","步槍","狙擊槍"]
//閉區(qū)間運(yùn)算符 輸出 "散彈槍","沖鋒槍","步槍","狙擊槍"
for name in nameArray[1...4] {
print(name)
}
//半開區(qū)間運(yùn)算符 輸出 "散彈槍","沖鋒槍","步槍"
for name in nameArray[1..<4] {
print(name)
}
//單側(cè)區(qū)間 輸出 "沖鋒槍","步槍","狙擊槍"
for name in nameArray[2...] {
print(name)
}
//輸出 "手槍","散彈槍","沖鋒槍"
for name in nameArray[...2] {
print(name)
}