dimanche 31 janvier 2016

If Statement: Compare multiple ints

I'm developing an app that is getting quite large after 1 year. So I'm trying to improve its performance in all aspects. I'm not a professional, I've been teaching myself programming for the past year, and when I look back some lines I wrote in the past they look so silly, like the one below:

    if (screenPos == 0 || screenPos == 20 || screenPos == 22){

//do something
} else {

}

Is there a simplest/shorter way to compare a value with several ints?

something like:

    if (screenPos != 0, 20, 22){
    //do something
} 

or maybe add this numbers in a array list and check "if(screenPos exists in the Array)"?

I know is a newbie question, sorry about that. I've been looking around for an answer, but haven't found it.

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire