JetBrains Rider 2018.2 Help

Code Inspection: Loop control variable is never changed inside loop

In the following code snippet

int j = 0; for (int i = 0; i < 10; j++) { ... }

the for loop variable is not varying. This causes the loop to execute indefinitely (unless for instance an exception occurs). JetBrains Rider warns us that there is nothing constraining the loop – it either fails immediately or it runs indefinitely. The error in the code above is caused by incrementing the incorrect variable ( j as opposed to i).

Last modified: 4 October 2018

See Also