for 循环
- OC 风格的循环
var sum = 0
for var i = 0; i < 10; i++ {
sum += i
}
print(sum)
for-in
,0..<10 表示从0到9
sum = 0
for i in 0..<10 {
sum += i
}
print(sum)
- 范围 0...10 表示从0到10
sum = 0
for i in 0...10 {
sum += i
}
print(sum)
- 省略下标
_
能够匹配任意类型_
表示忽略对应位置的值
for _ in 0...10 {
print("hello")
}
时间: 2024-10-11 18:25:39