A for loop tests one variable and steps another, so its condition never changes

tx0/csharp:loop-steps-other-variabledefaultwarningreliability/control-flowdepth fastbug

What it finds

for (int j = 0; j < n; i++) declares and tests j but increments i; unless the body changes j, the loop never ends or never runs. This typically comes from copying an outer loop. The rule reports a for loop that declares one variable, tests it in the condition, steps only other variables, and does not change it in its body.

From the rule's source, loop_steps_other_variable.rs.

Example from the rule's tests
class Grid{    void Fill(int[,] cells, int rows, int columns)    {        for (int i = 0; i < rows; i++)        {            for (int j = 0; j < columns; i++)tx0 reports: the loop tests j but steps i            {                cells[i, j] = 1;            }            for (int j = 0; j < columns; j++)            {                cells[i, j] = 2;            }        }    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/csharp:loop-steps-other-variable" = "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-steps-other-variable] reason="..."

tx0 explain tx0/csharp:loop-steps-other-variable shows the same in the terminal. Found a false positive? Report it.