Skip to main content

noUnnecessaryContinue (since v0.7.0)

This rule is recommended by Rome.

Avoid using unnecessary ContinueStatement.

Examples

Invalid

loop: for (let i = 0; i < 5; i++) {
continue loop;
}
error[js/noUnnecessaryContinue]: Unnecessary continue statement
   js/noUnnecessaryContinue.js:2:3
  
2    continue loop;
     ^^^^^^^^^^^^^^

Suggested fix: Delete the unnecessary continue statement
    | @@ -1,3 +1,2 @@
0 0 |   loop: for (let i = 0; i < 5; i++) {
1   | -   continue loop;
2 1 |   }

while (i--) {
continue;
}
error[js/noUnnecessaryContinue]: Unnecessary continue statement
   js/noUnnecessaryContinue.js:2:3
  
2    continue;
     ^^^^^^^^^

Suggested fix: Delete the unnecessary continue statement
    | @@ -1,3 +1,2 @@
0 0 |   while (i--) {
1   | -   continue;
2 1 |   }

while (1) {
continue;
}
error[js/noUnnecessaryContinue]: Unnecessary continue statement
   js/noUnnecessaryContinue.js:2:3
  
2    continue;
     ^^^^^^^^^

Suggested fix: Delete the unnecessary continue statement
    | @@ -1,3 +1,2 @@
0 0 |   while (1) {
1   | -   continue;
2 1 |   }

for (let i = 0; i < 10; i++) {
if (i > 5) {
console.log("foo");
continue;
} else if (i >= 5 && i < 8) {
console.log("test");
} else {
console.log("test");
}
}
error[js/noUnnecessaryContinue]: Unnecessary continue statement
   js/noUnnecessaryContinue.js:4:5
  
4      continue;
       ^^^^^^^^^

Suggested fix: Delete the unnecessary continue statement
    | @@ -1,7 +1,6 @@
0 0 |   for (let i = 0; i < 10; i++) {
1 1 |     if (i > 5) {
2 2 |       console.log("foo");
3   | -     continue;
4 3 |     } else if (i >= 5 && i < 8) {
5 4 |       console.log("test");
6 5 |     } else {

for (let i = 0; i < 9; i++) {
continue;
}
error[js/noUnnecessaryContinue]: Unnecessary continue statement
   js/noUnnecessaryContinue.js:2:3
  
2    continue;
     ^^^^^^^^^

Suggested fix: Delete the unnecessary continue statement
    | @@ -1,3 +1,2 @@
0 0 |   for (let i = 0; i < 9; i++) {
1   | -   continue;
2 1 |   }

test2: do {
continue test2;
} while (true);
error[js/noUnnecessaryContinue]: Unnecessary continue statement
   js/noUnnecessaryContinue.js:2:2
  
2      continue test2;
       ^^^^^^^^^^^^^^^

Suggested fix: Delete the unnecessary continue statement
    | @@ -1,3 +1,2 @@
0 0 |   test2: do {
1   | - 	continue test2;
2 1 |   } while (true);

Valid

while (i) {
if (i > 5) {
continue;
}
console.log(i);
i--;
}

loop: while (1) {
forLoop: for (let i = 0; i < 5; i++) {
if (someCondition) {
continue loop;
}
}
}