0

我有一个转换后的 for 循环Swift 3.2,看起来类似于:

for var i in 0..<char.characters.count {
    if(self.characters.count > len  && ((currentIndex + length2323) < length))
    {
      i = i - 1
    }
}

但是,它不能正常工作。i我想在为is设置值时继续循环,i = i - 1但是这段代码超出了循环

我以前Swift 2的代码是:

for(var i = 0 ; i < char.characters.count ; i += 1) {
     if(self.characters.count > len  && ((currentIndex + length2323) < length))
     {
        i = i - 1
     }
}
4

2 回答 2

0
for (index, item) in char.enumerated()
{
      //your loop
}
于 2018-01-31T12:48:43.370 回答
0

斯威夫特 4 语法

import UIKit
var char = "char"
var len = 9
var currentIndex = 1
var length2323 = 2323
var length = 17
for var i in 0..<char.count {
if (self.count > len)  && ((currentIndex + length2323) < length) {
    i = i - 1
}

}

斯威夫特 3.2 语​​法

import UIKit
var char = "char"
var len = 9
var currentIndex = 1
var length2323 = 2323
var length = 17
for var i in 0..<char.characters.count {
if (self.characters.count > len)  && ((currentIndex + length2323) < length) {
    i = i - 1
}

}

于 2018-01-31T12:14:19.043 回答