Self Java, day03_Java out of the break and continue statements

Jump statements break

  • Role: termination switch or cycle
  • Scenarios : selecting switch statement structure or loop statement
  • Note: leaving the scene of the existence of use does not make sense

demand

Illustrates basic use of break

Code Example

public  class Demo14Break {
     public  static  void main (String [] args) {
         for ( int I =. 1; I <= 10; I ++ ) {
             // if desired starting from the 4th, do not follow all, it is necessary to interrupt the cycle 
            IF (I == 4) { // if the current is the fourth 
                BREAK ; // then the entire cycle interrupt 
            } 
            System.out.println ( "the Hello" + I); 
        } 
    } 
}

Results of the

Bounce statement: continue

  • Role: the end of this cycle, the next cycle continues
  • Application scenarios : In the loop statement
  • Note: leaving the scene of the existence of use does not make sense

demand

Illustrate the basic usage continue

Code

public  class Demo15Continue {
     public  static  void main (String [] args) {
         for ( int I =. 1; I <= 10; I ++ ) {
             IF (I == 4) { // if the current is the fourth layer 
                Continue ; // then skip the current cycle, immediately starts the next (fifth layer) 
            } 
            System.out.println (I + "to the layer." ); 
        } 
    } 
}

Results of the

 

Guess you like

Origin www.cnblogs.com/wurengen/p/11521117.html