Why this matters
Using 'continue' in loops creates unstructured control flow, making the code harder to read and maintain. Replace it with clearer conditional logic to improve readability.
Detect the use of 'continue' inside loops. This practice can make control flow harder to follow. Recommend restructuring the loop for better readability.
Using 'continue' in loops creates unstructured control flow, making the code harder to read and maintain. Replace it with clearer conditional logic to improve readability.
Side-by-side examples engineers can pattern-match during review.
for (i = 0; i < 10; i++) {
if (i == 5) {
continue; /* Noncompliant */
}
alert("i = " + i);
} for (i = 0; i < 10; i++) {
if (i != 5) { /* Compliant */
alert("i = " + i);
}
} for (i = 0; i < 10; i++) {
if (i == 5) {
continue; /* Noncompliant */
}
alert("i = " + i);
} for (i = 0; i < 10; i++) {
if (i != 5) { /* Compliant */
alert("i = " + i);
}
}From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.