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