Why the strange indentation on switch statements?

后端 未结 6 1146
太阳男子
太阳男子 2021-02-04 23:11

Why is the imho missing indentation of the \"case\" - keywords in a switch statement considered good style?

No indentation of the \"case\" keyword seems to be the defaul

6条回答
  •  耶瑟儿~
    2021-02-04 23:48

    Maybe it is to keep the same indentation level as its logical equivalent expressed in if statments? That is:

    switch(i){
    case 0:
      //do something 1
    case 1:
      //do something 2
    }
    

    Would look similar to its logical equivalent:

    if(i==0){
      //do something 1
    }else if(i==1){
      //do something 2
    }
    

提交回复
热议问题