Labeled for loop in java, Example 2

Java Programming Language / Decision Making and Looping in java

1154

Program:

public class LabeledForLoop {
public static void main(String[] args) {
  firstlooplebel:
    for(int i=1;i<=4;i++){
       secondlooplebel:
          for(int j=1;j<=4;j++){
               if(i==2&&j==2){
                  break secondlooplebel;
                 }
             System.out.println(i+" "+j);
           }
       }
   }
}

Output:

1 1
1 2
1 3
1 4
2 1
3 1
3 2
3 3
3 4
4 1
4 2
4 3
4 4
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.