我有一个与循环和迭代有关的问题
我有一种情况:
for (Item *item in items)
{
if (condition)
{
iterateAgain;
}
}
由Objective-C提供的continue
运算符将以一个新的迭代开始。操作员break
将打破整个循环。
实现此目的的最佳方法是什么?
您不能使用快速枚举,这似乎是您正在使用的。改用基于索引的循环:
NSSet *items = [Model items];
NSArray *itemsArray = [items allObjects];
for (NSInteger index = 0; index < [itemsArray count]; index++) {
Item *item = itemsArray[index];
// ...
if (condition) {
index = 0;
// Possibly use 'continue' here, depending what else is in the loop
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句