// 区间运算符
for i in 1..<5 {
print(i)
}
let name = ["zhangsan","Lisi","wangwu","zhaoliu"]
for name in name[..<2] {
print(name)
}
// range 没有开始区间,所以不能进行循环,但是可以用来判断是否包含。
let range = ...5
print(range.contains(7))
print(range.contains(-1)) // 5以下的都是 true.
let range2 = "a"..."z"
let hello = "Hello,World"
for char in hello {
if !range2.contains(String(char)) {
print("\(char) 不是小写字母")
}
}
运行结果:
image.png
网友评论