相关疑难解决方法(0)

为什么在OOP中使用break/continue标签是不好的做法(例如Java,C#)?

我被告知在OOP语言中使用break和continue标签不是OOP编程风格.你能详细解释一下原因和问题是什么吗?

诀窍在于这个标签词.我的意思是打破/继续.

class BreakWithLabelDemo {
    public static void main(String[] args) {

        int[][] arrayOfInts = {
            { 32, 87, 3, 589 },
            { 12, 1076, 2000, 8 },
            { 622, 127, 77, 955 }
        };
        int searchfor = 12;

        int i;
        int j = 0;
        boolean foundIt = false;

    search:
        for (i = 0; i < arrayOfInts.length; i++) {
            for (j = 0; j < arrayOfInts[i].length;
                 j++) {
                if (arrayOfInts[i][j] == searchfor) {
                    foundIt = true;
                    break search;
                }
            }
        } …
Run Code Online (Sandbox Code Playgroud)

c# java oop continue break

8
推荐指数
3
解决办法
2万
查看次数

标签 统计

break ×1

c# ×1

continue ×1

java ×1

oop ×1