31 lines
676 B
Plaintext
31 lines
676 B
Plaintext
The use of ``++break++`` with a label is only needed to break out of multiple, nested control blocks, and this kind of usage adds further complication to already complex code, making it difficult to maintain. Instead the code should be restructured so that a label ``++break++`` isn't required.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,text]
|
|
----
|
|
outer: for (int i = 0; i < outerLimit; i++) {
|
|
for (int j = 0; j < innerLimit) {
|
|
if (i * j == 400) {
|
|
break outer; // Noncompliant
|
|
}
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,text]
|
|
----
|
|
int j = 0;
|
|
for (int i = 0; i < outerLimit && i * j != 400; i++) {
|
|
for (; j < innerLimit) {
|
|
// ...
|
|
}
|
|
}
|
|
----
|
|
|