Jumping from one case to the default case in switch statement

前端 未结 9 920
予麋鹿
予麋鹿 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:20

    Just reorder the cases so that that case is the last:

    switch(ch){
              case 'b':
                     //..
              case 'c':
                     //..
              case '_':
                     //...
              case 'a':
                     //do something, condition does not match so go to default case
                     if (condition)
                         break;
                     //don't break in here, and don't allow fall through to other cases.
              default:
                     //
                     break;
    }
    

提交回复
热议问题