how to stop a for loop

前端 未结 8 1929
长情又很酷
长情又很酷 2020-11-27 03:00

I\'m writing a code to determine if every element in my nxn list is the same. i.e. [[0,0],[0,0]] returns true but [[0,1],[0,0]] will return false.

8条回答
  •  一整个雨季
    2020-11-27 03:21

    To stop your loop you can use break with label. It will stop your loop for sure. Code is written in Java but aproach is the same for the all languages.

    public void exitFromTheLoop() {
        boolean value = true;
                loop_label:for (int i = 0; i < 10; i++) {
                  if(!value) { 
                     System.out.println("iteration: " + i);
                  break loop_label;
            }
        }
    }   
    

    }

提交回复
热议问题