Is there any easier way of checking one variables value against several others? Currently I’m using code like this:
if(a[i] == a[i-13] || a[i] == a[i+13] || a[i] == a[i-1] || a[i] == a[i+1]){
//my code
}
Now, is there a shorter way to do this? I know I can use a switch, but then I’d have to write my function several times. Is there an easier way of doing this?
You do not need to write your function several times with a switch:
Amusingly, however, this is just about the same number of characters (depending on how you format it). A switch statement in general is less powerful than an explicit
ifstatement, but in this case I find it clearer and less error-prone.