Skip to main content

CRR0023 - Unnecessary conditional

This analyzer detects conditional statements that always evaluate to true because of the conditional statement above. A possible example is shown in the code snippet below.

if(a) {
    if(b) {
        DoSomething();
    }
    else {
        if(a) {
            DoSomethingElse();
        }
    }
}

Consider the flowchart of the code snippet given above.

Analyzers_CRR0023

If you trace the program flow, you will see that the highlighted branch is never reached, which means the conditional statement around the DoSomethingElse function is redundant and can be removed.

if(a) {
    if(b) {
        DoSomething();
    }
    else {
        DoSomethingElse();
    }
}