swift 学习笔记(12)-区间运算符

前端之家收集整理的这篇文章主要介绍了swift 学习笔记(12)-区间运算符前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

区间运算符(…),一般用于 for 循环

//1~10 包括10
1...10
for index in 1...10{
    print( index)
}
//半开区间运算符
//1~10 不包括10
for index in 1..<10{
    print(index)
}
var names = ["name1","name2","name3","name4","name5"]
names[1...3]

for index in 0 ..< names.count{
    print("name:\(names[index])")
}

names[0...1] = ["zhangsan","lisi"]
print(names)
原文链接:https://www.f2er.com/swift/322665.html

猜你在找的Swift相关文章