How to break a while loop from an if condition inside the while loop?

后端 未结 3 985
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-20 11:12

I want to break a while loop of the format below which has an if statement. If that if statement is true, the while loop also must break. Any help would be appreciated.

3条回答
  •  孤城傲影
    2020-12-20 12:17

    An "if" is not a loop. Just use the break inside the "if" and it will break out of the "while".

    If you ever need to use genuine nested loops, Java has the concept of a labeled break. You can put a label before a loop, and then use the name of the label is the argument to break. It will break outside of the labeled loop.

提交回复
热议问题