Jump out multiple cycles

zhaozj2021-02-16  69

Use the BREAK statement intelligently to jump out of this layer loop, but sometimes you want to jump out two or more loops how to deal with? I think there are two ways. The first way is to use a goto statement, such a large-scale transfer, how many layers of cycles are jumped out. But well known, GOTO statement is conflicted by most programmers because it violates structured? Second, I want to make a bit more troublesome, it is to set a flag before jump out (for example, give a BOOL type variable Flag assignment), then judge in the second layer loop, select the second layer loop or continue Execute the second layer. However, the disadvantage of this is that if you want to jump out of the multi-layer loop, you may need multiple flag variables. You can solve the problem in most of you only need a FLAG. How to choose these two methods will have the situation. I don't know if there is any other way.

转载请注明原文地址:https://www.9cbs.com/read-20447.html

New Post(0)