When using fast enumeration, is there a way to exit early, i.e. before going through every element in the array?
for (element in myArray)
{
//is there a way to exit before running through every element in myArray?
}
When using fast enumeration, is there a way to exit early, i.e. before going through every element in the array?
for (element in myArray)
{
//is there a way to exit before running through every element in myArray?
}
break;
将退出任何for
, while
, 或do
循环。
例如:
for (element in myArray)
{
if (someExitCondition)
{
break; /* leave now */
}
}
读这个:
http://msdn.microsoft.com/en-us/library/wt88dxx6(v=vs.80).aspx
更好的方法是使用块
[dict enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
stop = YES // To break the loop }];