How to continue outer loop in Java

2 Answers

0 votes
class Program {
    public static void main(String[] args) {
        mainloop: 
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 4; j++) {
                if (i * j > 5) {
                    System.out.println("continue mainloop");
                    continue mainloop;
                }
                System.out.println(i + " " + j);
            }
        }
        
        
    }
}



/*
run:

0 0
0 1
0 2
0 3
1 0
1 1
1 2
1 3
2 0
2 1
2 2
continue mainloop
3 0
3 1
continue mainloop
4 0
4 1
continue mainloop

*/

 



answered Apr 24, 2025 by avibootz
0 votes
class Program
{
    static int[] a = new int[]{ 4, 5, 1, 1, 6, 7, 0, 1, 1, 1, 8};
    static int[] b = new int[]{ 9, 1, 2, 7 };
     
    public static void main (String[] args) {
    	mainloop: 
    	for (int vala:a) {
    		for (int valb:b) {
    			if (vala == valb) {
    				continue mainloop;
    			}
    		}
    		System.out.print(vala + " ");
    	}
    }
}



/*
run:

4 5 6 0 8 

*/

 



answered Apr 24, 2025 by avibootz

Related questions

1 answer 115 views
115 views asked Apr 24, 2025 by avibootz
1 answer 151 views
1 answer 102 views
102 views asked Apr 25, 2025 by avibootz
3 answers 169 views
...