samedi 29 août 2015

Best way to use if / else [on hold]

Whats the best way to use an if/else query, when I cant check different conditions in one query?

Example 1

public void method1()
{
    if(condition1 == true)
    {
        if(condition2 == true)
        {
            if(condition3 == true)
            {
                //do something
            }
        }
    }
}

Example 2

public void method2()
{
    if(condition1 == fale)
    {
        return;
    }
    if(condition2 == false)
    {
        return;
    }
    if(condition3 == false)
    {
        return;
    }

    //do something
}

I think Example 2 is much clearer, but is Example 1 the better way?


Aucun commentaire:

Enregistrer un commentaire