Skip to main content

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

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.
if (condition) { // CRR0011
  DoSomething();
  return;
}

if (condition)
  DoSomethingElse();

Consider the flowchart of the code snippet given above.

Analyzers_CRR0011

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.