使用stride(from:to:by:)函数来太哦过不想要的标记
闭区间也同样适用,使用stride(from:through:by:)即可
code
//: A UIKit based Playground for presenting user interface
import UIKit
let minuteInterval = 5
for tickMark in stride(from: 0, to: 50, by: minuteInterval){
print(tickMark)
}
print("---")
for tickMark in stride(from: 0, through: 50, by: minuteInterval){
print(tickMark)
}
结果
0
5
10
15
20
25
30
35
40
45
---
0
5
10
15
20
25
30
35
40
45
50
结论 to 为开区间。throuugh是闭区间。by 是步长
repeat-while 循环
类似java的do while
code
//: A UIKit based Playground for presenting user interface
import UIKit
var count = 0
repeat{
print(count)
count+=1
} while count < 5
count = 0
repeat{
print(count)
count+=1
} while count < 0
结果
0
1
2
3
4
0