samedi 8 août 2020

Best practice to use multi if statements [closed]

I am curious about how can I use a multi if statements like this with the best performance.

    if UserNotActive(){
        // do job 1
    }else if UserCanWriteSomeThing(){
        // do job 2
    }else if UserMessageIsSomeMessage(){
        // do job 3
    }else if TheTimeIsMidNight(){
        // do job 4
    }// and whatever

method names are fake, but my code is something like this and maybe they are more than 10 or 15

What is the best syntax for this code? Can I use Switch?

Aucun commentaire:

Enregistrer un commentaire