Java – name a loop

While browsing through questions and answers on this forum, I found that a piece of code was given loops to use them for interrupts like

nameofloop:
    for(){
        for(){
             if(){ break nameofloop;}
        }
    }

My new programming I didn't see before My question is, what are the other uses of named loops?

Solution

This is not a tag loop, just a tag you put anywhere, and then you can "break" or "continue" according to your conditions You can also use nested if else to loop to break multiple loops decorated with if else, so you can avoid setting many flags and test them in if else to continue the level in this nesting

It is discouraged, similar to goto, and leads to spaghetti code

Personally, I have been using it once before to break one of the other two loops. If it is else, I will continue the loop in the external loop, because the break in the loop will interrupt the loop, but the outermost thing to continue in the external loop is my case

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>