Use break and continue keywords
break: the end of the current cycle
continue: ended when cycles
Examples are as follows
class JavaTest{ public static void main(String[] args){ // Get the number of milliseconds the current time from the 1970-01-01 00:00:00 long start = System.currentTimeMillis(); System.out.println(start); label : for(int i = 1; i <= 4; i++){ System.out.print ( "first" + i + "cycles:"); flag:for(int j = 1; j <= 5; j++){ if(j <= i){ System.out.print(j + " "); }else{ System.out.print("\n"); //break flag; continue flag; } } } } }