Index

no-continue

禁止 continue 语句

❄️ Frozen

此规则目前已 冻结,不接受功能请求。

continue 语句终止当前迭代中当前或标记循环的语句执行,并继续执行下一次循环迭代。当使用不当时,它会使代码的可测试性、可读性和可维护性降低。应该改用像 if 这样的结构化控制流语句。

🌐 The continue statement terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration. When used incorrectly it makes code less testable, less readable and less maintainable. Structured control flow statements such as if should be used instead.

let sum = 0,
    i;

for(i = 0; i < 10; i++) {
    if(i >= 5) {
        continue;
    }

    sum += i;
}

规则详情

🌐 Rule Details

此规则不允许使用 continue 语句。

🌐 This rule disallows continue statements.

此规则的错误代码示例:

🌐 Examples of incorrect code for this rule:

在线运行
/*eslint no-continue: "error"*/

let sum = 0,
    i;

for(i = 0; i < 10; i++) {
    if(i >= 5) {
        continue;
    }

    sum += i;
}
在线运行
/*eslint no-continue: "error"*/

let sum = 0,
    i;

labeledLoop: for(i = 0; i < 10; i++) {
    if(i >= 5) {
        continue labeledLoop;
    }

    sum += i;
}

符合此规则的正确代码示例:

🌐 Examples of correct code for this rule:

在线运行
/*eslint no-continue: "error"*/

let sum = 0,
    i;

for(i = 0; i < 10; i++) {
    if(i < 5) {
       sum += i;
    }
}

选项

🌐 Options

此规则没有选项。

🌐 This rule has no options.

兼容性

🌐 Compatibility

  • JSLintcontinue

版本

此规则是在 ESLint v0.19.0 中引入。

资源