Two 'case' items

closed account (jwkNwA7f)
How can I do a switch with two keys?

For example:
1
2
3
4
5
switch(KeyStroke)
{
case VK_CONTROL: // and 'C'
...
}


Thank you in advance!
Last edited on
There's a quirk in C++ that lets you use multiple cases to activate something.
1
2
3
4
5
6
7
8
9
10
11
12
switch(variable){
   case 1:
   case 2:
   case 3:
      dosomething();
      break;
   case 4:
   case 5:
      dosomethingelse();
      break;
   default: break;
};


As soon as one case matches, the following instructions are executed until a break is reached, which includes executing other cases whether or not they match. This is also why when you forget to put any breaks in your switch statement, the program goes into an infinite loop.
closed account (jwkNwA7f)
Oh, okay.

I had read about that a while ago, but forgot about it.

Thank you!
Last edited on
Topic archived. No new replies allowed.