A while loop tests only local variables that its body never changes, and has no other exit
What it finds
When the condition of a loop reads only local variables and constants, and the body neither changes any of those variables nor leaves the loop with break, return, throw, goto or yield, the condition has the same value on every round: the loop either never runs or never ends. Usually an increment or a reassignment is missing. A variable that a lambda or local function captures counts as changed.
From the rule's source, loop_condition_unchanged.rs.
class Waiting{ int Spin(int limit) { int i = 0; int total = 0; while (i < limit)tx0 reports: nothing in the loop changes i, limit, and the loop has no other exit { total += 2; } while (i < limit) { i++; } bool done = false; while (!done) { done = Step(); } return total; } bool Step() => true;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/csharp:loop-condition-unchanged" = "off"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-condition-unchanged] reason="..."tx0 explain tx0/csharp:loop-condition-unchanged shows the same in the terminal. Found a false positive? Report it.