The counter of a for loop is also changed inside its body
What it finds
A for loop says in its header how its counter moves; changing the counter in the body as well makes the number of rounds hard to see and easy to break. A while loop says that the steps vary.
From the rule's source, loop_counter_assigned.rs.
class Scan{ int Count(string text) { var count = 0; for (int i = 0; i < text.Length; i++) { if (text[i] == '\\') { i++;tx0 reports: the loop counter i is also changed in the body } count++; } return count; }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:loop-counter-assigned" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:loop-counter-assigned] reason="..."tx0 explain tx0/csharp:loop-counter-assigned shows the same in the terminal. Found a false positive? Report it.