for (i = 1 ; i < 100 ; i = i*2)这样和循环变量i相关的循环怎么用swift表示?
这种情况用for循环比较麻烦,先要构建一个等比数列。用while循环容易实现:
var i = 1 while(i < 100) { // Do something i *= 2 }
for i in stride(from: 1, to: 100, by: 2){}