This loop will never execute - will execute with negative and decrementing

In relation to csharpsquid:S2252, causing a false positive

This looks like it would be an easy fix, probably just setup for the common case of incrementing non-negative numbers. The underline in SonarCloud is on the n > -0.1 so presume there is an assumption in there incorrectly.

        public void ForLoop_StartZeroEndNegativeIncrementNegative_DoesExecute(double start, double end, double step)
            var hasBeenCalled = false;
            for (var n = 0.0; n > -0.1; n -= 0.005)
                hasBeenCalled = true;

Hello @SimonLegg

Thanks for reporting this problem.
I can confirm it as a false positive. I opened an issue where you can track the progress.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.