Java Control statements
Control Statement 1.1 Sequence Structure (most common)
Feature: code execution from top to bottom
1.2 select structure:
If judgment statement:
Switch judgment statement:
Note:
1. After each statement ends, a break is required to prevent switch penetration.
2. The switch statement can only be used to determine the amount of variable int, short, char, byte String (available only after JDK 7)
3. The data following Case must be constants.
Advantages of switch statements: clear statement structure and fast running speed.
Disadvantages of the switch statement:
The switch that can be implemented by If is not necessarily feasible, and the switch can be implemented by if.
1.3 Loop Structure
While loop: first judge the execution
Structure:
While (loop condition ){
Loop body.
}
Do while loop: Execute first and then judge. The loop body will certainly execute once.
Structure:
Do {
Loop body;
} While (Cyclic condition );
For Loop:
Structure:
For (;;){
Loop body
}