Switch/case - number of cases based on user input?

Hi, I've been trying to workout how I can control the number of cases in a switch/case statement based on user input. Is it possible?

Jamie

What do you mean "control the number"?

The number of cases in the statement:

input = 8;
switch (menu_levels){
   case 1:
      //code
   break;
   ...
   case 8:
      //code
   break;
}

What do you mean by "control"?
You can have as many cases as you like - I don't understand your question.

What I would like to achieve is this; A rotary encoder is turned to increment a variable, that variable is used to define how many cases (menu levels) are used in the switch statement.

Jamie

No. You can't.

You could always provide as many cases as the maximum possible number from you user input, and just not use all of them.

You can't have a variable number of cases, but you can have a different switch for each sub-menu, which is what I think you're asking.

You still have to code them all - whether you then use them all is different.
Say your code supports up to 15 - but your rotary encoder says only 0-8 as options at any one time. So user is only presented choices 0-8. 9-14 still have to exist.

Thanks, that clears that up!

Jamie