JetBrains Rider 2024.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: 11 February 2024