This loop is there exclusively only in java it is not even there C#. Labeled loop should be used in the following situations when we create one loop within another loop it it called as nested loop and in case of nested loop if we break internal loop by giving a condition outer loop will continue to work as it is in such cases if we want to loop stop imminently in such cases the movement the inner loop stop we should use some label for outer loop the same label should be used in the break in the statement
Ex of label loop
public class LabelLoop{
public static void main(String[] args){
int i ,j;
//Outer loop
outer; //label
for(i=1; i<=10; i++){
System.out.println();
inner; //label
for(j=1; j<=10; j++){
System.out.println(j+" ");
if(j==9)
break inner;
}
}
}
}
Comments
Post a Comment