Break statement inside two while loops

后端 未结 11 1221
时光取名叫无心
时光取名叫无心 2020-12-24 14:00

Let\'s say I have this:

while(a){

  while(b){

   if(b == 10)
     break;
 }
}

Question: Will the break statement take m

11条回答
  •  不思量自难忘°
    2020-12-24 14:37

    Only from the inner one. Use labeled break if you wish to break to specific loop

    label1:
    for(){
      label2:
      for(){
          if(condition1)
          break label1;//break outerloop
    
          if(condition2)
          break label2;//break innerloop
      }
    }
    

    Also See

    • labeled break

提交回复
热议问题