所以迅速改变了他们不能做的for循环
for (i = 0; i <10; i++){ //do some stuff }
你只能这样做
for i in 0...100 { //do some stuff }
我的问题是在哪里i
把i = i + 1?
我试图把它的for
功能,但它不能正常工作.
如果需要增加除1之外的其他值,则使用stride创建范围:
for i in stride(from: 0, to: 10, by: 2) { print (i) // 0,2,4,6,8 } for i in stride(from: 0, through: 10, by: 2) { print (i) // 0,2,4,6,8,10 } for i in stride(from: 0, through: 10, by: 2).reversed() { print (i) // 10,8,6,4,2,0 }