samedi 28 mars 2020

Long "if...continue" chains vs "if...else" chains in Javascript? [closed]

I couldn't find this question already on stack overflow (if it exists please point me in the right direction):

I have a long chain of if...continue statements that unfortunately don't transfer to a switch statement:

while (thing is true)
    if (condition 1) {
        ...do something; continue;
    }
    if (condition 2) {
        ...do something; continue;
    }
    ...
    if (condition 10) {
        ...do something; continue;
    }
}

Is there any difference (performance-wise or "good style"-wise) between this and making a long if-else chain?

while (thing is true)
    if (condition 1) {
        ...do something;
    }
    else if (condition 2) {
        ...do something;
    }
    ...
    else if (condition 10) {
        ...do something;
    }
}

Aucun commentaire:

Enregistrer un commentaire