Process control
Judgment statement
if (judgment condition) {
If it is true, execute the program in the if statement
}else{
If it is false, execute the program in the ielse statement
}
Multi-branch select statement
Switch statement: Refers to a multi-branch selection statement. The parameters in the switch are used to determine which statement is selected to be executed. Later, the switch statement is jumped out through break. For simple judgments, his judgment is more efficient.
If the statement is not found with If the condition matches the case and there is no default statement, it will jump out of the switch statement and continue to execute downward.
for loop
The basic syntax is
for(int i=0;i<100;i++){
循环体
}
或者for(;i<100;i++){
}
也可以 for(;;){
这样的写法是死循环
}
while loop
while (condition) { loop body } If the condition is true, it is an endless loop
do-while loop
do{ loop body }(condition) is executed at least once
The difference between the three cycles
The for loop is suitable for specifying the number of loops, while is used for continuous loops, and do-while loops at least one word.
continue statement
-
Used to skip the outer loop closest to continue, usually used for loop statements.
-
If the inner loop j==5 here jumps out of this inner loop, then it is impossible to output 5 every time -
Can also be used to skip a marked cycle
-
Use C here to mark that it will jump out of the outer loop