java-based judgment statement cycle

1.if statements, switch statements, for loops, while loops, do-while loop

  (1) if the statement in three formats: 

                 if (condition) {
               meet the condition statement to be executed
                            }

           -----------------------------------

    if (condition) {

     Eligible for execution statement
    } else {

     Does not meet the conditions of the statement to be executed
         }

         -----------------------------------------  

    if (condition 1) {
    meet the condition statement is executed 1

    } Else if (condition 2) {

    Condition 2 statement to be executed
    } else if (condition 3) {

    Matching 3 statement to be executed
    } .... else {statement to be executed under the above conditions are not met}

 

=================================================================================

       (2) switch statement format:

    switch (variable) {short byte int char enumeration String
    Case Value 1:
    variable statement in line with the value of 1 to be executed;
    BREAK;
    Case Value 2:
    Variable statement in line with the value of 2 to execute
    BREAK;
    ......
    default:
    Variable statements do not meet the above conditions to be executed
    }

    (. 1) penetrating the case: variable switch statement on a case once a match value, when there is no break is encountered, the switch statement will not be judged, the code executed in the order from top to bottom

    (2) Note: swtich statement can only be used byte \ char \ short \ int \ enum \ String type, a switch statement may default statement or case statement does not appear, do not even appear also OK

 ==============================================================================

   (3) for loop format:    

         for (initialization statement ①; loop conditional statement ②; conditional control statements ③) {

            Loop statement ④
          }

==============================================================

   (4) while loop format:

              Initialization statement;
            the while (loop condition determination) {
                 loop statement
                 controls conditional statement
              }

        (1) Direct infinite loop: while (true) {}

====================================================================

         (5) do-while loop format: 

      Initialization statement;
        do {
          loop statement
            conditional control statements

          } while (loop conditional statement);

             (1) while the difference between the do-while: while the first determination is performed again

               do-while and then to execute judgment, regardless of whether the conditions are met, it will perform at least once

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/suitang/p/11517330.html
Recommended