public class Br{
public static void main(
String argv[]){
Br b = new Br();
b.amethod();
}
public void amethod(){
for(int i=0;i <3;i ++){
System.out.println("i"+i+"\n");
outer://<==Point of this example
if(i>2){
break outer;//<==Point of this example
}//End of if
for(int j=0; j <4 && i<3; j++){
System.out.println("j"+j);
}//End of for
}//End of for
}//end of Br method
}
I was trying above example from
linkhttp://www.jchq.net/certkey/0202certkey.htm
got output like
i0
j0
j1
j2
j3
i1
j0
j1
j2
j3
i2
j0
j1
j2
j3
I was trying to understand the output.Where outer label used in this loop. When we say outer does it mean below outer label if loop or above outer label for loop. Do we need to see below label or above label. Is it suppoesed to be i>2 or i>=2.
same way could not undestand
public class LabLoop{
public static void main(String argv[]){
LabLoop ml = new LabLoop();
ml.amethod();
}
public void amethod(){
outer:
for(int i=0;i<2;i++){
for(int j=0;j<3;j++){
if(j>1)
//Try this with break instead of continue
continue outer;
System.out.println("i "+ i + " j "+j);
}
}//End of outer for
System.out.println("Continuing");
}
}
This version gives the following output
i 0 j 0
i 0 j 1
i 1 j 0
i 1 j 1
Continuing
If you were to substitute the continue command with break, the i counter would stop at zero as the processing of the outer loop would be abandoned instead of simply continuing to the next increment.