Having an unconditional break, return or throw in a loop renders it useless; the loop will only execute once
and the loop structure itself is simply wasted keystrokes. The same is true for a conditional structure where every condition leads to a jump out of
the loop.
Having an unconditional continue in a loop is itself wasted keystrokes.
For these reasons, unconditional jump statements should never be used except for the final return in a function or method.
for (i = 0; i < 10; i++) { // Noncompliant
console.log("i is " + i);
break; // loop only executes once
}
for (i = 0; i < 10; i++) {
console.log("i is " + i);
continue; // Noncompliant; this is meaningless; the loop would continue anyway
}
for (i = 0; i < 10; i++) { // Noncompliant
console.log("i is " + i);
return; // loop only executes once
}
for (i = 0; i < 10; i++) { // Noncompliant; loop only executes once
console.log("i is " + i);
if (i < 5) {
break;
} else {
return;
}
}
for (i = 0; i < 10; i++) {
console.log("i is " + i);
}