Skip to main content

js/noUnnecessaryContinue

This rule detects continue statements that can be marked as unnecessary. These statements can be safely removed.

Examples

Invalid

loop: for (let i = 0; i < 5; i++) {
	continue loop;
}

 file.ts:2:1 lint/js/noUnnecessaryContinue  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━

  Unnecessary continue statement

    1loop: for (let i = 0; i < 5; i++) {
  > 2  continue loop;
       ^^^^^^^^^^^^^^
    3}

  Safe fix

  - continue·loop;


while (i--)
		continue;

 file.ts:2:2 lint/js/noUnnecessaryContinue  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━

  Unnecessary continue statement

    1while (i--)
  > 2    continue;
         ^^^^^^^^^

  Safe fix

  - continue;


while (1) {
	continue;
}

 file.ts:2:1 lint/js/noUnnecessaryContinue  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━

  Unnecessary continue statement

    1while (1) {
  > 2  continue;
       ^^^^^^^^^
    3}

  Safe fix

  - continue;


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

 file.ts:4:8 lint/js/noUnnecessaryContinue  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━

  Unnecessary continue statement

    2     if (i > 5) {
    3         console.log('foo');
  > 4         continue;
              ^^^^^^^^^
    5     }
    6     else if (i >= 5 && i < 8) {

  Safe fix

  - continue;


for (let i = 0; i < 9; i++) {
	continue;
}

 file.ts:2:1 lint/js/noUnnecessaryContinue  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━

  Unnecessary continue statement

    1for (let i = 0; i < 9; i++) {
  > 2  continue;
       ^^^^^^^^^
    3}

  Safe fix

  - continue;

Valid

while (i) {
	if (i > 5) {
		continue;
	}
	console.log(i);
	i--;
}
while (i) {
	continue;
	console.log(i);
}
while (condition) {
	if (conditionZ) {
		if (conditionX) {
			console.log('log');
			continue;
		}
		console.log('log');
		if (conditionY) {
			console.log('log');
		}
	}
}
loop: while (1) {
	forLoop: for (let i = 0; i < 5; i++) {
		if(someCondition) {
			continue loop;
		}
	}
}
loop: for (let i = 0; i < 10; i++) {
	for (let j = 0; j < byteLength; j++) {
		if (condition) {
			continue loop;
		}
	}
}