希望在for-in循环中比较几个int和一个数组:
for i in 0...47 where i != someNumber && i != someOtherNumber && i != myArrayOfAFewNumbers[] {
doSomething()
}
我似乎找不到简单的解决方案。谢谢!
答案 0 :(得分:2)
首先创建一个排除项目的数组,例如:
let excludedItems = [someNumber, someOtherNumber] + myArrayOfAFewNumbers
for i in 0...47 where !excludedItems.contains(i) {
doSomething()
}
您也可以使用Set
来达到更好的复杂性:
let excludedItems = Set([someNumber, someOtherNumber] + myArrayOfAFewNumbers)