| Property | Value |
|---|---|
| Package | Philips.CodeAnalysis.MaintainabilityAnalyzers |
| Diagnostic ID | PH2127 |
| Category | Maintainability |
| Analyzer | AvoidUsingParametersAsTempVariablesAnalyzer |
| CodeFix | No |
| Severity | Error |
| Enabled By Default | Yes |
Inside the loop, do not change the loop variables. This makes the loop logic harder to read and can cause unexpected behavior.
Instead of changing the loop variable, use continue or break to control the loop flow.
Code that triggers a diagnostic:
public class BadExample {
public void BadLoop() {
for (int i = 0; i < 5; i++) {
if (someCondition) {
i = 5;
}
}
}
}And the replacement code:
public class GoodExample {
public void GoodLoop() {
for (int i = 0; i < 5; i++) {
if (someCondition) {
break;
}
}
}
}This analyzer does not offer any special configuration. The general ways of suppressing diagnostics apply.