ReSharper
 
Get ReSharper
You are viewing the documentation for an earlier version of ReSharper.

Code Inspection: Loop control variable is never changed inside loop

Last modified: 21 July 2022

In the following code snippet

the for loop variable is not varying. This causes the loop to execute indefinitely (unless for instance an exception occurs). ReSharper 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).