Do an OR in Switch-Case in C++
c++, visual-studio-2010
Solution
Cases fall through without a break:
case 27: //could be 27
case 'q': //could be 27 or 'q'
case 'Q': //could be 27, 'q', or 'Q'
exit(0);
break;
Problem
How would you do this in C++? For example I'm trying to trigger a program exit both if the user presses ESC or 'q' or 'Q'. I've tried looking for it, but I found no syntax for it in C++. I know how to do it with if-else, but is it possible with switch - case? Of course I can just make a function and call it from two separate case, but is there a way to do it just by combined case statement? For example that's what I'm looking for (of course not working): ``` void keyboard( unsigned char key, int x, int y ) { switch( key ) { case ( 27 || 'q' || 'Q' ): exit( 0 ); break; case 'a': ... case 'b': ... } } ```