Lint Rules

noUnnecessaryContinue (since v0.7.0)

This rule is recommended by Rome.

Avoid using unnecessary continue.

Examples

Invalid

loop: for (let i = 0; i < 5; i++) {
  continue loop;
}
correctness/noUnnecessaryContinue.js:2:3 lint/correctness/noUnnecessaryContinue  FIXABLE  ━━━━━━━━━━

   Unnecessary continue statement
  
    1 │ loop: for (let i = 0; i < 5; i++) {
  > 2 │   continue loop;
     ^^^^^^^^^^^^^^
    3 │ }
    4 │ 
  
   Suggested fix: Delete the unnecessary continue statement
  
    1 1  loop: for (let i = 0; i < 5; i++) {
    2  - ··continue·loop;
    3 2  }
    4 3  
  
while (i--) {
  continue;
}
correctness/noUnnecessaryContinue.js:2:3 lint/correctness/noUnnecessaryContinue  FIXABLE  ━━━━━━━━━━

   Unnecessary continue statement
  
    1 │ while (i--) {
  > 2 │   continue;
     ^^^^^^^^^
    3 │ }
    4 │ 
  
   Suggested fix: Delete the unnecessary continue statement
  
    1 1  while (i--) {
    2  - ··continue;
    3 2  }
    4 3  
  
while (1) {
  continue;
}
correctness/noUnnecessaryContinue.js:2:3 lint/correctness/noUnnecessaryContinue  FIXABLE  ━━━━━━━━━━

   Unnecessary continue statement
  
    1 │ while (1) {
  > 2 │   continue;
     ^^^^^^^^^
    3 │ }
    4 │ 
  
   Suggested fix: Delete the unnecessary continue statement
  
    1 1  while (1) {
    2  - ··continue;
    3 2  }
    4 3  
  
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");
  }
}
correctness/noUnnecessaryContinue.js:4:5 lint/correctness/noUnnecessaryContinue  FIXABLE  ━━━━━━━━━━

   Unnecessary continue statement
  
    2 │   if (i > 5) {
    3 │     console.log("foo");
  > 4 │     continue;
       ^^^^^^^^^
    5 │   } else if (i >= 5 && i < 8) {
    6 │     console.log("test");
  
   Suggested fix: Delete the unnecessary continue statement
  
     2  2    if (i > 5) {
     3  3      console.log("foo");
     4   - ····continue;
     5  4    } else if (i >= 5 && i < 8) {
     6  5      console.log("test");
  
for (let i = 0; i < 9; i++) {
  continue;
}
correctness/noUnnecessaryContinue.js:2:3 lint/correctness/noUnnecessaryContinue  FIXABLE  ━━━━━━━━━━

   Unnecessary continue statement
  
    1 │ for (let i = 0; i < 9; i++) {
  > 2 │   continue;
     ^^^^^^^^^
    3 │ }
    4 │ 
  
   Suggested fix: Delete the unnecessary continue statement
  
    1 1  for (let i = 0; i < 9; i++) {
    2  - ··continue;
    3 2  }
    4 3  
  
test2: do {
	continue test2;
} while (true);
correctness/noUnnecessaryContinue.js:2:2 lint/correctness/noUnnecessaryContinue  FIXABLE  ━━━━━━━━━━

   Unnecessary continue statement
  
    1 │ test2: do {
  > 2 │ 	continue test2;
   	^^^^^^^^^^^^^^^
    3 │ } while (true);
    4 │ 
  
   Suggested fix: Delete the unnecessary continue statement
  
    1 1  test2: do {
    2  - continue·test2;
    3 2  } while (true);
    4 3  
  

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;
    }
  }
}