Skip to content

Files

Latest commit

 

History

History
30 lines (20 loc) · 583 Bytes

Generic.CodeAnalysis.ForLoopShouldBeWhileLoop.md

File metadata and controls

30 lines (20 loc) · 583 Bytes

Pattern: Use of for instead of while loop

Issue: -

Description

Detects for loops that can be simplified as a while loop.

Example

Example of incorrect code:

// no Init or Update part
for (;$test;) {
    $test = doSomething();
}

Example of correct code:

for ($i = 0; $i < 10; $i++) {
    echo "{$i}\n";
}

Further Reading