How to do a case with multiple conditions?

后端 未结 5 573
傲寒
傲寒 2020-12-29 21:57

In the 1 month experience I\'ve had with any programming language, I\'ve assumed that switch case conditions would accept anything in the parenthes

5条回答
  •  囚心锁ツ
    2020-12-29 22:28

    You can achieve an OR for cases like this:

    switch (someChsr) {
    case 'w':
    case 'W':
        // some code for 'w' or 'W'
        break;
    case 'x': // etc
    }
    

    Cases are like a "goto" and multiple gotos can share the same line to start execution.

提交回复
热议问题