break in a case with return.. and for default

前端 未结 13 1987
予麋鹿
予麋鹿 2020-12-11 14:19

My OCD makes me add \"break\" when writing case statements, even if they will not be executed. Consider the following code example:

switch(option) {
    cas         


        
13条回答
  •  有刺的猬
    2020-12-11 15:09

    I agree with having a break in a final default case, and don't agree with breaks after returns. (A colleague does those and it hurts my eyes.)

    I also indent switches so as to reduce proliferation of indent levels. :) i.e.:

    switch(option) {
    case 1:
        a = 1;
        b = 7;
        break;
    case 2:
        a = 2;
        b = 4;
        return -1;
    default:
        a = -1;
        break;
    }
    

    (I also think that, since the return statement is not a function, it isn't appropriate to enforce a superfluous style that makes it look like one.)

提交回复
热议问题