I want to use switch statement with 2 variables, for example, a and b, something like this:
switch(a,b){
case(1,1): // a = 1 and b = 1
doSomething()
break
case(1,2): // a = 1 and b = 2
doSomethingElse()
break
case(0,2): // a = 0 and b = 2
doOtherthings()
break
default
doNothing()
}
I know this code doesn't work, so is there any alternative way to do this?
You could use if statements instead.
if (a === 1 && b === 1) doSomething();
else if (a === 1 && b === 2) doSomethingElse();
else if (a === 0 && b === 2) doOtherthings();
else doNothing();