Java serialized 24-break statement, continue statement, the number of output quality practice

A, break

1.break Java language keywords, translated as "interruption / break"

2.break + ";" can become a single complete java statement: break;

3.break statement uses a switch statement is used to execute the termination switch statement

4.break statement can be used in the same loop, the loop is executed to terminate

Which loop 5.break termination?

6.break; statements used for \ while \ do ... while loop statement out of the loop to terminate execution of the loop, because when the cycle time to a condition subsequent cycle is not necessary to perform, and also in the implementation of resource-intensive, it can terminate the loop, so you can improve the performance of programs

7. Use the following for loop to explain the break; statement

8. By default break interrupt that cycle closest to him

 

    for(int j = 0;j<3;j++) {

      for(int i=0;i<10;i++) {

        if(i==5) {

          break;

        }

        System.out.println("i --->" + i);

    }

 

9. If I wanted to break the outer loop how to do?

Answer: the need to cycle named using this syntax: break the cycle name

example:

 

    for1:for(int j = 0;j<3;j++) {

      for2:for(int i=0;i<10;i++) {

        if(i==5) {

          break for1;

        }

        System.out.println("i --->" + i);

       

      }

    }

Two, continue statement:

1.continue said: continue, go on, next

2.continue is also a key pick a semicolon continue to constitute a single complete sentence of java, occurred mainly among the executed loop to control the loop

And continue the difference 3.break

(1) break represents the end, the execution of the loop no longer

(2) continue to terminate this denotes "this" cycle, directly into the next cycle continues.

4.continue can also specify the names continue to perform the operation.

 

    for(int i=1;i<10;i++) {

      if (i == 5) {

        continue;

      }

      System.out.println("i = "+i);

    }

 

5. Exercise: primes output between 1 to 100, eight line

 

// output primes between 1 to 100, eight line 

    int In Flag = 1 ; 

    of System.out.print ( 2 + "" ); 

    for ( int I = 2; I <= 100; ++ I) { 

      for ( int J = 2; J <I; ++ J) { 

        IF (% I J == 0 ) { 

          BREAK ; 

        } 

        IF (I-J ==. 1 ) { 

          of System.out.print (I + "" ); 

          In Flag ++ ; 

          IF (. 8% In Flag == 0 ) { 

            of System.out.print ( "\ n-" ); 

          } 

        }        

      }

    }

 

Third, the source code:

d24_break_and_continue_exercise_and_output_prime_number.java

address:

https://github.com/ruigege66/Java/blob/master/d24_break_and_continue_exercise_and_output_prime_number.java

2.CSDN: https: //blog.csdn.net/weixin_44630050 (Xi Jun Jun Moods do not know - Rui)

3. Park blog: https: //www.cnblogs.com/ruigege0000/

4. Welcomes the focus on micro-channel public number: Fourier transform, backstage reply "gifts" to get big data learning materials

 

 

Guess you like

Origin www.cnblogs.com/ruigege0000/p/11444427.html