Program Flow Control 1

Beijing Fengtai Credit Card Repayment [Tel/WeChat: 135-2093-5605] Beijing Fengtai Credit Card Cash Out, Visa Card Cash Out, Points POS Machine Valid for a long time Welcome to inquire for processing! Process control: We often need to change the program during program design The control flow, that is, the execution order of the statements. There are three basic techniques for changing the flow of control of a program  

[1]: Invoking a method: Invoking a method causes the flow of control to leave the current method and transfer to the called method. For example, when we call println() method, flow control leaves main(), transfers to println(), and returns to main() method when println() method execution is complete.  

【2】: Select. There are two mechanisms for making choices in java: the if/else statement and the switch statement. The ternary operator can also be used for selection, but it is usually just a shorthand version of if/else.  

【3】: Cycle. There are three kinds of looping statements in java: for loop, while loop, do/while loop.  

2:  

Boolean logic: refers to combining two or more Boolean expressions into a single Boolean expression. There are four types of logic for combining boolean expressions; as follows.  

[1]: and. A composite expression is true only if each part of the composite expression is true.  

【2】: or. A composite expression is true as long as one of its parts is true.  

[3]: Exotic. A composite expression is true if one part of a composite expression is true and the other part is false.  

【4】: No. Negate a boolean expression.  

3:  

switch statement: The switch statement allows a variable to be checked for equality with multiple values, each called and checked by a case statement. The syntax of a switch statement is of the form:  

switch(variable) {  
      case value:  
            //statement 
           break; //optional  
        case value:  
           //statement  
           break; //optional  
           //there can be many case statements  
         default; //optional  
           //statement  
} The  

following rules apply to switch statement:  

[1]: The detected in the switch statement Variables can only be 32-bit or smaller integer values, that is, they can only be of type byte, short, int, and char (Note: After JDK7.0, variables can be of type String).  

[2]: There can be many case statements in a switch statement. Each case is followed by a value for comparison and a colon.  

[3]: The value after case must be the same data type as the variable in switch, and must be a constant or literal.  

[4]: When the value of the variable is equal to the value after the case, the statement after the case statement starts to execute until the break statement is encountered.  

[5]: When a break statement is encountered, the switch statement ends, and the control flow jumps to the next line of the switch statement.  

[6]: Not all case statements need to contain a break statement. If there is no break statement, the flow of control continues to the next case statement until a break statement is encountered. 

[7]: A switch statement can have an optional default condition, which usually appears at the end of the switch statement. A default condition can be used to perform a certain task if all case conditions are false. A break statement is not required in a default condition.  

4:  

continue statement: The keyword can be used in any loop control structure, it will cause the loop to jump immediately to the next iteration of the loop.  

[1]: In a for loop, the continue keyword will cause the control flow to immediately jump to the update statement.  

[2]: In a while or do/while loop, the control flow immediately jumps to the Boolean expression.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326727864&siteId=291194637