jeudi 27 juillet 2017

Shorten If Statement And Making It Less Redundant

new here. I was just wondering if it's possible to make this if statement shorter and less redundant.

if (!a && b)
{
    if (c == d && e > 0)
    {
        return;
    }
}
else if (a && !b)
{
    if (c != d)
    {
        return;
    }
}
else if (!a && !b)
{
    return;
}

Here's what I've ended up with

if ((!a && b && c == d && e > 0) || (a && !b && c != d) || (!a && !b))
{
    return;
}

All I did was join nested if statements with an && operator, and if-else if statements with || operator. Now I'm stuck, is it possible to make this even shorter? If you could share some tips or your way of approaching this kind of scenario, I'd be glad to hear it out.

Aucun commentaire:

Enregistrer un commentaire