ccoding-stylecurly-bracesswitch-statement

'break' statement when using curly braces in switch-case


I use curly braces with all of my switch case statements in C/Objective-C/C++

I had not, until a few moments ago, considered whether including the break; statement inside the braces was good or bad practice. I suspect that it doesn't matter, but I figure it is still worth asking.

    switch (foo) {
        case 1: {
            // stuff
            break;
        }

        default: {
            break;
        }
    }

vs

    switch (foo) {
        case 1: {
            // stuff
        } break;

        default: {
            // stuff
        } break;
    }

Solution

  • Short answer: it doesn't matter.