Skip to content

Instantly share code, notes, and snippets.

@pethaniakshay
Last active June 23, 2025 00:47
Show Gist options
  • Save pethaniakshay/2015b7ec6081667b7fdc74fde50c186e to your computer and use it in GitHub Desktop.
Save pethaniakshay/2015b7ec6081667b7fdc74fde50c186e to your computer and use it in GitHub Desktop.
Example of Labeled For Loop in Java
public class LabeledForLoop{
public static void main(String args[]){
outer_loop:
for(int i=0 ; i<5 ; i++){
inner_loop:
for(int j=0 ; j<5 ; j++){
if(i==2 || j ==4){
break outer_loop;
}
else{
System.out.print(i + "-"+ j + " ");
}
}
System.out.println();
}
}
}
public class SimpleForLoop{
public static void main(String args[]){
for(int i=0 ; i<5 ; i++){
for(int j=0 ; j<5 ; j++){
if(i==2 || j ==4){
break;
}
else{
System.out.print(i + "-"+ j + " ");
}
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment