Basic if selection structure: situations where a single or combined condition can be handled
if (condition) {--> result must be a Boolean value
Suggested omitting {} when there is only one statement in code block
}
IF-ELSE selection structure: Can handle simple conditional branching situation
if () {
Code Block 1
}else{
Code Block 2
}
Multiple if selection structure: A conditional branching condition that can handle continuous intervals
if (condition 1) {
Code Block 1
}else if (condition 2) {
Code Block 2
}else{
Code block 3
}
Nested IF selection structure: can handle complex conditional branching situations
if (condition 1) {
if (condition 2) {//code block 1
}else{//Code 2
}else{//Code 3
}
}
Switch selection structure: Multiple branches and condition judgment is the case of equivalence judgment
switch (expression)--integer or character {
case constant 1; Statement Break
case constant 2; Statement Break
......
default--> if no matching value is found
Statement
Break
}
Note: Break cannot be omitted, constants cannot be the same, expressions cannot be strings
The similarities and differences between the multiple if selection structure and the switch selection structure:
The same point: all structures used to handle multi-branch conditions
Different points:
Switch selection structure: can only handle the condition of the equivalent condition judgment, and the condition must be an integer or character type variable
Multi-Select structure: No switch-selection structure, especially when a variable is in a contiguous state
Java selection structure