JetBrains Rider 2023.1 Help

Code Inspection: Loop control variable is never changed inside loop

This inspection reports loops that are not constrained — they either fail immediately or run indefinitely. In the following code snippet

public void Test(bool condition) { while(condition) { // do something } }

the loop variable condition is not varying, which causes the loop to execute indefinitely (unless for instance an exception occurs). In this synthetic example the problem is obvious, but if there is a lot of code inside the loop, you might never notice that until the program hangs at runtime.

Last modified: 05 December 2022