Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java中断循环不工作_Java_Android_Breakpoints - Fatal编程技术网

java中断循环不工作

java中断循环不工作,java,android,breakpoints,Java,Android,Breakpoints,我的java代码中有一个break标签,但当我转到代码中的break语句时,它不会跳转到标签: OUTERMOST:for(String s :soso){ if(wasBreaked){ //code never enters this loop Log.e("","WASBREAK = FALSE"); wasBreaked = false; }

我的java代码中有一个break标签,但当我转到代码中的break语句时,它不会跳转到标签:

  OUTERMOST:for(String s :soso){

        if(wasBreaked){
              //code never enters this loop
                Log.e("","WASBREAK = FALSE");
                wasBreaked = false;
        }

        if(true){
                Log.e("","WASBREAK = TRUE GOING TO OUTERMOST");
                wasBreaked = true;
                break OUTERMOST;
        }
  }

Break语句并不像在其他编程语言(如C)中那样是goto语句

相反,您的代码所做的是,从具有最外层标签的循环中中断。我原以为你需要
在最外面继续而不是中断。但对我来说,这真的没有意义,因为在继续后没有任何语句(现在代码中出现中断),不管你是否明确地说继续,它都会继续

public class Test {

   public static void main(String[] args) {

    String soso[]={"1","2"};
    boolean wasBreaked=false;
    OUTERMOST:for(String s :soso){

        if(wasBreaked){
                Log.e("","WASBREAK = FALSE");
                wasBreaked = false;
        }

        if(true){
                Log.e("","WASBREAK = TRUE GOING TO OUTERMOST");
                wasBreaked = true;
                System.out.println("before break");

                break OUTERMOST;//use continue in place of break here for going to label
                }
        System.out.println("Inside outermost loop");
}
    System.out.println("outside outermost loop");

}

}
我试过这个,效果很好 它提供输出

   before break
   outside outermost loop
要返回标签,您应该在代码中使用continue关键字,而不是break。使用continue后,输出如下

 before break
 before break
 outside outermost loop

这不起作用,因为在最外层中断
并不意味着
跳到最外层
。这意味着打破标签
最外层的循环,它不应该跳转到标签
break
不是
goto
(Java中没有
goto