你能解释一下Swift的优势及其奇特的用途吗?
e.g :
for i in stride(from: 0, to: 10, by: 1) {
print(i) // prints from 0 to 9
}
除此之外,我们还可以使用for
循环。
答案 0 :(得分:1)
您的问题似乎是询问stride
对基本for
循环的好处,其范围为1..<10
。
stride
支持按1以外的值递增。
// count by 3
for x in stride(from: 3, to: 30, by: 3) {
}
// Backwards
for n in stride(from: 20, to: 0, by: -4) {
}
stride
适用于非整数值。
for r in stride(from: 3.14, to: 234.14234, by: 5.6345) {
}