Code Inspection: Loop control variable is never changed inside loop

 

int calibCount = getCalibCount(); //calibCount is loaded from USB device and can be different based on device

...
for (var calibCounter = 0; calibCounter < calibCount; calibCounter++)
{
    ...
}

calibCount realy not changed inside loop, but I think this should not be reported, because it is correct.

It is not the case described in: "https://www.jetbrains.com/help/resharper/2016.3/LoopVariableIsNeverChangedInsideLoop.html"

Am I wrong about it?

If yes how could look the code that will not generate the warning?

 

Thanks in advance for your answer.

2
2 comments

I'm seeing this as well in latest Rider and Resharper. I'm having a hard time reproducing it outside of the original codebase. Here is the loop itself: 

for (var i = 0; i < count; i++) {
var property = properties[i];
if (property.propertyPath == path) {
ph = property;
break;
}
}

Curiously, if I get rid of the break, the warning pops down to a similar loop lower in the method. I'm pretty sure this is a bug, as I have tested and this loop does in fact get past i == 0.

0

Hello Mtschoen!

 

Thank you for the feedback.

Do I understand correctly that the issue is reproduced in some specifc solution only? Could you please try suggestion from the following article?

Thank you.

0

Please sign in to leave a comment.