Code exercises--break and continue

/**Special flow control statement
         * break statement: used to terminate the current loop (end the current loop);
         * continue: used to end the current loop and directly enter the next loop
         * return: end a method, when one When the method executes to a return statement, this method ends
         * Note: break--can only be used for switch statements and loop statements
         * continue--can only be used for loop statements
         *
        
        //nested loop
        System.out.println("complete The loop result of ");
        for(int i = 1;i <5;i++){             for(int j = 1;j <4;j++){                 System.out.print(i); //print(): input The result does not wrap                 System.out.print(j); //println(): The input result wraps automatically                 System.out.println();             }




        }
        System.out.println();
        System.out.println();
        
        //break: terminate the current loop
        System.out.println("test break statement: end the current loop");
        for(int i = 1 ;i <5;i++){             for(int j = 1;j <4;j++){                 if(j == 2){                     break;                 }                 System.out.print(i);                 System.out.print(j) ;                 System.out.println();             }







        }
        System.out.println();
        System.out.println();
        
        
        //continue: end this loop and enter the next loop
        System.out.println("Test the continue statement: end this loop and enter the next loop ");
        for(int i = 1;i <5;i++){             for(int j = 1;j <4;j++){                 if(j == 2){                     continue;                 }                 System.out.print(i) ;                 System.out.print(j);                 System.out.println();             }







        }
        System.out.println();
        System.out.println();
        
        
        //return: terminate the method
        System.out.println("Test the return statement: terminate this method directly");
        for(int i = 1;i < 5;i++){             for(int j = 1;j <4;j++){                 if(j == 2){                     return;                 }                 System.out.print(i);                 System.out.print(j);                 System. out.println();             }







        }
         */
        

Guess you like

Origin blog.csdn.net/weixin_42248871/article/details/109227277