Skip to content

avoid_unnecessary_continue

v1.0.0 Warning Fix Control Flow

This rule flags a continue written as the last statement of a loop body, where control reaches the next iteration whether it is there or not.

The keyword changes nothing, but it does not read as though it changes nothing. continue announces that something below it is being skipped, so a reader stops to look for what — and finds the closing brace.

It is usually a leftover. Statements that once followed the continue were moved or deleted during a change, and the guard that protected them stayed behind. Removing it makes the loop say what it does.

A continue anywhere else is doing real work and is left alone, including one that ends a then branch to skip an else, and a labelled continue that targets an outer loop.

for (final order in orders) {
process(order);
continue; // nothing follows; the loop continues anyway
}
for (final order in orders) {
process(order);
}

A continue that actually skips something stays:

for (final order in orders) {
if (order.isCancelled) continue; // skips the call below
process(order);
}

This rule is in the opinionated preset.

To disable this rule:

many_lints.yaml
rules:
avoid_unnecessary_continue: false

To keep the rule on but skip certain paths, use per-rule exclude.