- Operating system: Win 10-64
- SonarLint plugin version: 7.2.0.76209
- Programming language you’re coding in: C# .Net 8
- Is connected mode used: No
S1264
states that a while
loop should be used when only the condition expression is defined in a for
loop. This makes sense:
Noncompliant code example
for (;condition;) { /*...*/ }
Compliant solution
while (condition) { /*...*/ }
However, the warning fires when the variable is declared outside of a for
loop. While rare, there are cases when one may do this, and no rule states one cannot do so.
Example:
int i;
for (i = 0; i < indexes.Count - 1;)
...