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.
Why use this rule
Section titled “Why use this rule”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);}Turning this rule off
Section titled “Turning this rule off”This rule is in the opinionated preset.
To disable this rule:
rules: avoid_unnecessary_continue: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_cascade_after_if_null— Detect cascades after if-null operators without parentheses.avoid_collapsible_if— Merge nested if statements with &&.avoid_constant_conditions— Detect comparisons where both sides are constants.avoid_constant_switches— Detect switch statements on constant expressions.