JetBrains Rider 2024.1 Help

Code Inspection: Loop control variable is never changed inside loop

Category

Potential Code Quality Issues

ID

LoopVariableIsNeverChangedInsideLoop

EditorConfig

resharper_loop_variable_is_never_changed_inside_loop_highlighting

Default severity

Warning

Language

C#

Requires SWA

No

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: 17 April 2024