Skip to main content

CRR0021 - Subsequent else-if conditions are identical

This analyzer detects a conditional statement containing the same conditional statement in its else branch. See the example below.

if (condition) {
    DoSomething();
} 
else if(condition) {
    DoSomethingElse();
}

In this code, the DoSomethingElse() function will never be executed because the second condition is checked only if the first condition is false. Since the conditions are similar, the program flow will never reach the body of the second conditional statement. To make it clear, look at the flowchart below on which the highlighted branch will never be reached.

Analyzers_CRR0011

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