Swift中for循环通过for...in... 实现,常用i++,i--方式有三种实现方式:
print("FlyELephant")
for index in 0..<10 {
print("\(index)\t", separator: "", terminator: "")
}
print("\nstride递增:")
for index in 0.stride(to: 10, by: 1) {
print("\(index)\t", separator: "", terminator: "")
}
print("\nReverse反转:")
for index in (0..<10).reverse() {
print("\(index)\t", separator: "", terminator: "")
}
print("\nstride递减:")
for index in 9.stride(to: -1, by: -1) {
print("\(index)\t", separator: "", terminator: "")
}
print("")