Home >Java >javaTutorial >control statements in java
Control statement
1.1 Sequential structure (the most common)
Features: The code is executed sequentially from top to bottom
1.2 Selection structure:
if Judgment statement:
switch Judgment statement:
Precautions for using the Switch statement :
1. There needs to be a break after each statement to prevent switch penetration.
2. The variables used for judgment in the switch statement can only be int, short, char, byte String (only available after jdk7)
3. The data following Case must be constant.
Advantages of switch statement: clear statement structure and fast running speed.
Disadvantages of the switch statement:
The switch that can be done by If may not be able to be done, and the if that can be done by switch can definitely be implemented.
1.3 Loop structure
While loop: first judge and execute
structure:
while (loop condition) {
loop body.
}
do while loop: execute first and then judge, the loop body will definitely be executed once.
Structure:
do{
loop body;
}while (loop condition);
for loop:
Structure:
for(;;){
Loop body
}