I want to use variables as the values for each case in a switch statement, but it doesnt seem to work:
switch(key) {
case keyNext:
//go to next
break;
case keyPrev:
//go to prev
break;
}
I really need the switch statement because unlike in this example, I have lots of different cases.
Why doesnt this work? Any workarounds for it?
EDIT: as said in the answers, this is perfectly valid. I was using properties of an object as the values for each case, and there was a syntax problem with it.
key? Is itevent.keycode? Yourswitchis syntactically correct, but how are you mapping keycodes tokeyNext, keyPrev? Are they defined by a framework?