1.2.242. Continue Is For Loop

break and continue are very similar in PHP : they both break out of loop or switch. Yet, continue should be reserved for loops.

Since PHP 7.3, the execution emits a warning when finding a continue inside a switch : ‘”continue” targeting switch is equivalent to “break”. Did you mean to use “continue 2”?’

<?php

while ($foo) {
    switch ($bar) {
        case 'baz':
            continue; // In PHP: Behaves like 'break;'
                      // In C:   Behaves like 'continue 2;'
    }
}

?>

See also Deprecate and remove continue targeting switch.

1.2.242.2. Connex PHP features

1.2.242.2.1. Suggestions

  • Replace continue by break

1.2.242.2.2. Specs

Short name

Structures/ContinueIsForLoop

Rulesets

All, Analyze, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70, CompatibilityPHP71, CompatibilityPHP72, CompatibilityPHP73

Exakat since

1.3.9

PHP Version

With PHP 7.3 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Examples

XOOPS

Available in

Entreprise Edition, Exakat Cloud