You can use the nested switch statement, but it can quickly become spaghetti code, and therefore is not recommended. I would rather use functions with a nested switch statement to encode the code, or perhaps use a recursive function depending on what the code should do.
This is just pseudo code, but I hope this gives you an idea of how to implement it. You must be careful to stop recursion at some given id value. This pseudo-code increases the value of the identifier by 1 if the ID value is 1 and increases by 2 if the value is 2. If the value is not 1 or 2, the recursion is completed.
function recursiveSwitch(var id) { switch(id) { case 1: recursiveSwitch(id + 1); break; case 2 recursiveSwitch(id + 2) break; default: return; } }
source share