Fourth chapter selection Structure (ii) What is the execution flow of the switch selection structure? Switch Select the function of the break keyword in the structure? This chapter aims to master the switch selection structure to solve the problem by using the If selection structure and switch selection structure. Why use the switch selection structure with multiple if selection structure--Cons: Complex structure, verbose use switch selection structure solution--Characteristics: The condition is equivalent to judge what is S Witch Select structure Switch Select structure switch (expression) {//integer or character case//constant 1: Evaluates the value of an expression statement; break;//if equals constant 1 case Constant 2://If equal to constant 2 statement; Default://If no matching value statement is found; break} Note: If you need to jump out after each case, do not forget to write Brea K. The constants following the case must be different, and the default block order can change, but be aware of the order in which they are executed. Usually, the default block is placed at the end, or it can be omitted. The value of the expression in the parentheses behind the switch must be an integer or a character-type comparison switch And the multiple if selection structure is the same point: all are used to deal with multi-branch conditions of the structure of different points: Switch selection structure can only handle the condition of the equivalence, and the condition must be an integer variable or the character variable multiple if selection structure does not have the restriction of switch selection structure, especially for the case where a variable is in a continuous interval. Select Structure Summary:
If selection structure
Basic if selection structure: situations where single or combined conditions are handled
IF-ELSE selection structure: Handling simple conditional branching situations
Multiple if selection structure: dealing with complex conditional branching situations
Nested IF selection structure: For more complex process Control
Switch selection structure
Multiple branches and condition judgment is the case of equivalence judgment.
Summarize:
Switch selection structure is applicable to condition judgment is the case of equivalence judgment
In practical applications, it is common to use multiple forms to select structural synthesis to solve more complex problems!
Java Chapter Fourth