I. Judgment statement:
1. If statement:
A. If (){
// Execute the statement;
}
B. If (){
// Execute the statement;
} Else {
// Execute the statement;
}
C. If (){
// Execute the statement;
} Else if {
// Execute the statement;
}
......
Else {
// Execute the statement;
}
2. Switch statement:
Switch (expression ){
Case constant expression 1: Statement 1;
Case constant expression 2: Statement 2;
......
Default: statement;
}
Ii. Loop statement:
1. For Loop statement:
For (Initial Value of the cyclic variable; cyclic condition; value-added value of the cyclic variable ){
Statement;
}
2. While loop:
While (condition ){
// Loop body;
}
3. Do while loop:
Do {
// Loop body;
} While (condition)
Iii. Differences between loop statements:
1. For and while loops:
For loops are mostly used to know the number of loops;
While loops are mostly used to determine the number of loops without knowing the number of loops;
2. Differences between a while loop and a do while loop:
Do while first executes the loop body, and then judges the condition. If the condition is met, continue the execution. If the condition is not met, exit the loop;
When a while loop first determines the condition, it executes the loop body and does not exit;