Back to Devexpress

CRR0003 - Suspect variable reference in the For-loop iterator section

coderushforroslyn-118092-static-code-analysis-analyzers-library-crr0003-suspect-variable-reference-in-the-for-loop-iterator-section.md

latest880 B
Original Source

CRR0003 - Suspect variable reference in the For-loop iterator section

  • Feb 28, 2025

This analyzer detects mistakes made in the for loop iterator expression. For instance, the for loop can increment one variable, but test another. This may lead to an incorrect number of iterations or even an infinite loop. It’s easy to make such a mistake when editing a copy of another loop.

csharp
for (int i = 0; i < n1; i++) {
    for(int j = 0; j < n2; i++) { // CRR0003
        // ...
    }
}

In the example above, the inner loop should increment variable “ j “.

csharp
for (int i = 0; i < n1; i++) {
    for(int j = 0; j < n2; j++) {
        // ...
    }
}

See Also

Suppress Analyzers