I'm working on a game and I have a variable id
. I need to compare that to multiple integers (lets say 10). I know you can simply use the ||
and do
if (id == 1 || id == 2 || id == 3)
which is perfectly fine, except in this case, I need to do that 10-15 times. Is there any quicker way to do this (it's the same variable that I'm comparing. Just different numbers).
I don't want an answer requiring a switch statement (which is also almost as much work). And I also don't want an answer using the ||
operator (like I showed in the code above).