Export (0) Print
Expand All

Dead Code Examples

Avoid writing redundant code.

In the following example, b++ is never reached:

a++;

return a;

b++;

return b;

In the following example, the break statement is never reached:

switch (type)

{

    case UtilElementType::Job:

         return false;

         break;

    ...    

In the following example, return a is never reached:

if (!a)

{

    throw error("@SYS21628");

    return a;

}

b++;

return b;

In the following example, the else statement is never used, because execution has already ended at the return statement:

if (a)

{

    return a;

}

else

{

    b++;

    return b;

}

Use this format instead:

if (a)

{

    return a;

}

b++;

return b;

Community Additions

ADD
Show:
© 2015 Microsoft