Switch statement using or

前端 未结 7 2412
时光说笑
时光说笑 2020-12-10 10:29

I\'m creating a console app and using a switch statement to create a simple menu system. User input is in the form of a single character that displays on-screen

7条回答
  •  忘掉有多难
    2020-12-10 10:51

    This way:

     switch(menuChoice) {
        case 'q':
        case 'Q':
            //Some code
            break;
        case 's':
        case 'S':
            //More code
            break;
        default:
     }
    

    More on that topic: http://en.wikipedia.org/wiki/Switch_statement#C.2C_C.2B.2B.2C_Java.2C_PHP.2C_ActionScript.2C_JavaScript

提交回复
热议问题