mercredi 31 juillet 2019

Scalable if statements conditions

I was wondering about the possibility of creating an if statement that is more scalable. In the case we have a condition that one variable can possibly be one of many different values for the if statement to be satisfied, I have tried these such formats:

This is the default answer.

if (variable == 23
    || variable == 52 
    || variable == 58 
    || variable == 62 
    || variable == 93)
{ 
    some function
} 

This is what I imagined would work as a newb to C.

if (variable == (23,52,58,62,93) 
{
    some function
}

However, using the comma method I get a warning such that

warning: expression result unused [-Wunused-value]

Does anyone have a possible way to make an if statement of one variable with multiple possible conditions to be written without copy and pasting the variable name each time?

Aucun commentaire:

Enregistrer un commentaire