Back to Devexpress

CRR0011 - Next if-statement has an identical condition that will never be reached

coderushforroslyn-118110-static-code-analysis-analyzers-library-crr0011-next-if-statement-has-an-identical-condition-that-will-never-be-reached.md

latest1.3 KB
Original Source

CRR0011 - Next if-statement has an identical condition that will never be reached

  • Feb 28, 2025

This analyzer detects the following situation.

  1. A conditional statement breaks the code flow (ends with the continue , break or return keyword).
  2. After that, there is a conditional statement with the same condition expression.
csharp
if (condition) { // CRR0011
  DoSomething();
  return;
}

if (condition)
  DoSomethingElse();
vb
If condition Then
  DoSomething()
  Return
End If

If condition Then
  DoSomethingElse()
End If

Consider the flowchart of the code snippet given above.

If you trace the program flow in both cases (when the condition is true and when it is false), you will see that the highlighted branch is never reached. This means that the body of the second conditional statement will never execute because the first conditional statement always breaks the code flow before it reaches the second conditional statement.

To fix this, remove the second conditional statement or change its condition expression so that it differs from the first one.

See Also

Suppress Analyzers