在 switch-case 中使用花括号时的“break"语句 [英] 'break' statement when using curly braces in switch-case

查看:37
本文介绍了在 switch-case 中使用花括号时的“break"语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C/Objective-C/C++ 中的所有 switch case 语句中都使用花括号

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

直到几分钟前,我才考虑在大括号内包含 break; 语句是好还是坏.我怀疑这无关紧要,但我认为这仍然值得一问.

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

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

        default: {
            // stuff
        } break;
    }

推荐答案

简答:没关系.

这篇关于在 switch-case 中使用花括号时的“break"语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆