vendredi 16 juillet 2021

If statement for multiple values of same variable

I want to apply if statement to check a condition with multiple value. Which i know should be something like this:

if (value==1 || value== 2 || value==3 || value==4)
    Do something;

But this does not look good, isn't there any way to check like:

if(value== 1 || 2 || 3 || 4 )

Note: I am not trying something in range like :

  if (1 <= value && value <= 4)

Aucun commentaire:

Enregistrer un commentaire