Jumping from one case to the default case in switch statement

前端 未结 9 1033
予麋鹿
予麋鹿 2021-01-03 22:59
switch(ch){
          case \'a\':
                 //do something, condition does not match so go to default case
                 //don\'t break in here, and don\'t         


        
9条回答
  •  半阙折子戏
    2021-01-03 23:10

    Well, the post is really old but to answer everyone: you can simple write 'goto default;' and you will directly jump to the default case without any problems.

    Example:

            switch (value)
            {
                case value1:
                   // do something;
                    break;
                case value2:
                   // do something
                    break;
               .
               .
               .
               .
                case value20:
                   // do something
                    **goto default;**
               .
               .
                case valueN:
                    // do something
                    break;
    
                default:
                    // do something
                    break;
            }
    

提交回复
热议问题