How can I break out of two nested for loops in Objective-C?

后端 未结 13 597
梦如初夏
梦如初夏 2020-12-01 00:49

I have two for loops nested like this:

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

    }
}

I know that there is a break statement. But I am con

13条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 01:24

    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;
          }
       }
    }
    

提交回复
热议问题