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

griotspeak picture griotspeak · Sep 10, 2011 · Viewed 19.3k times · Source

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;
    }

Answer

Oliver Charlesworth picture Oliver Charlesworth · Sep 10, 2011

Short answer: it doesn't matter.