jeudi 25 novembre 2021

Does exiting function with return sooner have any practical value

Let's assume I have these two functions:

function foo(int $a): void
{
    if ($a > 5) {
        doThis();
        return;
    }

    doThat();
}

function bar(int $a): void
{
    if ($a > 5) {
        doThis();
    } else {
        doThat();
    }
}

Is there any practical advantage of exiting the function rather than using else statement?

Aucun commentaire:

Enregistrer un commentaire