与回报的情况下打破..和违约 [英] break in a case with return.. and for default

查看:77
本文介绍了与回报的情况下打破..和违约的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的OCD让我加破发文具盒语句时,即使他们不会被执行。请看下面的code例如:

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

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

我的两个问题是:

对于案例2:我并不真的需要休息,但它是一个不错的主意,有在那里呢?
对于默认。它是纯粹的强迫症​​,或有任何真正的理由在这里有突破?

My two questions are:
For "case 2:", I don't really need the break, but is it a good idea to have it there anyway? For "default:". Is it purely OCD, or is there any real reason to have the break here?

推荐答案

您不需要任何休息,但没有坏处有他们。在我看来,让您的code结构是值得拥有的一对夫妇外来语句。

You don't need either break, but there's no harm in having them. In my opinion, keeping your code structured is worth having a couple of extraneous statements.

这篇关于与回报的情况下打破..和违约的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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