rspec/rules/S3045/rule.adoc

33 lines
704 B
Plaintext

== Why is this an issue?
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) {
// ...
}
}
----