本文介绍了我怎样才能摆脱两个嵌套在Objective-C的循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个嵌套这样的循环:

I have two for loops nested like this:

for(...) {
    for(...) {

    }
}

我知道有一个语句。但我感到困惑,如果它打破了,它被称为两个循环或只是一个?我需要尽快打破那些都像我看到它没有什么意义了迭代次以上。

I know that there is a break statement. But I am confused about if it breaks both loops or just the one in which it was called? I need to break both ones as soon as I see that it doesn't make sense to iterate more times over.

推荐答案

break中断一个循环的,但你可以检查添加到外环打破当内休息。

break breaks out of one loop, but you can add a check to the outer loop which breaks when the inner breaks.

bool dobreak = false;
for ( ..; !dobreak && ..; .. ) {
   for ( ... ) {
      if (...) {
         dobreak = true;
         break;
      }
   }
}

这篇关于我怎样才能摆脱两个嵌套在Objective-C的循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 11:57