Can switch case have more than one value per case?

My IR remote uses Philips RC5 under which protocol each consecutive key press of the same key toggles what it sends. The volume down key, for instance, sends 1041 the first time, then 3089 the next, and back to 1041 for the third and so on. In my program I'm not fussed what it sends, I only want to know which key was pressed, so I want to do the same thing regardless of getting a 1041 or 3089. (Slow my robot down, as it happens.)

So far I coded it with an if:

if (results.value == 1041 || results.value == 3089) {
      // do slowing down stuff
        }

Of course I now have a zillion ifs to handle all the keys, which gets a bit untidy. Switch case always struck me as a more elegant way of working through choices so I wondered if it has a similar way of handling the same action for various cases.

Guessing, I tried this:

switch (value) {
  case 1041: ||  3089:
    // statements
    break;
   }

and this:

 switch (value) {
  case 1041: || case 3089:
    // statements
    break;
   }

In both cases I got this compile error:

sketch_jun25b:4: error: expected primary-expression before '||' token

So is there a way of having more than one value per case, or do I have to code it longhand like this:

 switch (value) {
  case 1041:
    // statements
    break;

  case 3089:
     // same statements as before
    break;
   }

Yes:

 switch (value) {
  case 1041:
  case 3089:
    // statements
    break;
   }

Why didn't I think of that option..... :blush:

Thanks Arrch,

Jim

Switch tutorial:

http://hacking.majenko.co.uk/node/43

Has all your answers.

Ah, so it works like that due to the lack of break in the upper case. Fiendishly cunning, that.