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

后端 未结 13 613
梦如初夏
梦如初夏 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:20

    Probably the easiest way is to use a "flag" variable

    for(i=0; i<10 && (done==false); i++)
      for(j=0;j< 10; j++){
         ..
         ..
         if(...){done=true; break;}
      }
    

提交回复
热议问题