gpt4 book ai didi

objective-c - ios打破嵌套循环

转载 作者:太空狗 更新时间:2023-10-30 03:21:16 25 4
gpt4 key购买 nike

如果我有一个 while 循环,在 while 循环的 内有一个 for 循环,我怎样才能打破两个循环?

我这样做是因为在我找到我想要的东西后,由于没有完成这些循环而增加的 250 毫秒加起来在一段时间后变得很有值(value)。

伪代码:

while(alwaysTrue) {
for(NSArray *arr in twoThousandItems) {
if(IFoundWhatIWasLookingFor) {
// assign some stuff here
// break everything, not just the for loop.
}
}
}

最佳答案

这就是 goto 是你的 friend 的地方。是的,goto

while(alwaysTrue) {
for(NSArray *arr in twoThousandItems) {
if(IFoundWhatIWasLookingFor) {
// assign some stuff here
// break everything, not just the for loop.
goto BAIL;
}
}
}
BAIL:
NSLog(@"Freedom!");

另一种选择是在您的环路中设置短路。

while(alwaysTrue && !found) {
for(NSArray *arr in twoThousandItems) {
if(IFoundWhatIWasLookingFor) {
// assign some stuff here
// break everything, not just the for loop.
found = YES;
break;
}
}
}

关于objective-c - ios打破嵌套循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9418972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com