Switch statement with returns — code correctness

前端 未结 17 2229
梦如初夏
梦如初夏 2020-12-12 20:05

Let\'s say I have code in C with approximately this structure:

switch (something)
{
    case 0:
      return \"blah\";
      break;

    case 1:
    case 4:
         


        
17条回答
  •  孤街浪徒
    2020-12-12 20:54

    I say remove them. If your code is so unreadable that you need to stick breaks in there 'to be on the safe side', you should reconsider your coding style :)

    Also I've always prefered not to mix breaks and returns in the switch statement, but rather stick with one of them.

提交回复
热议问题