dimanche 18 décembre 2016

c format of multiple conditions

I am implementing a simple if statement in c, where I am comparing the value of integer 'tile' to four other integers: w, a, s and d.

Here is my code:

if(tile == w || tile == a || tile == s || tile == d )
{
    printf("legal\n");
    return true;
}

While the above is correct, the syntax is tiresome. Is there a more elegant way of writing the condition "'tile' is one of the following integers..."

I'm a novice in programming so I apologise as I suspect the answer is very ovbious. I've failed to find it addressed elsewhere though.

Thanks

Aucun commentaire:

Enregistrer un commentaire