Before I start this question I know the java 'goto' is a big no go.
So I've been writing a program and I have some indented Loops and statements and I need to BREAK
multiple on command. Rather than having a load of boolean
variables and if(!<booleanName>) BREAK;
statements throughout these loops and statements what is everyone's opinions on using labels to break them using the BREAK <label>
statement?
e.g.
for(...) {
indented_example_loops: // Label name
for(...) {
for(...) {
if(match) break indented_example_loops;
// ^ Break statement to break the 2 for loops at once
}
}
}
Perfectly okay? Okay to do occasionally? Completely avoid? or should i go to a corner and call the Devil to take my soul?
return
instead ofbreak
. Structured programming was invented more than 40 years ago (en.wikipedia.org/wiki/Structured_program_theorem) for good reasons.break
,continue
,throw
,switch
, andreturn
are all forms of the much malignedgoto
. Some of this is warranted, some is not. Labels can make these structures easier to read or harder. Treat them all with respect.