1. Break
The use of the break statement is mainly the switch statement and the loop structure.
Use the break statement in the loop structure to exit the loop and then execute the first statement below the loop structure.
If a break statement is used in a multiple nested loop, when the break statement is executed, the loop structure in which it resides is exited, and the outer layer loop has no effect.
If a switch statement is in the loop structure and a break statement is used in the switch statement, when the break statement in the switch statement is executed, only the switch statement is exited, and the outer loop structure is not exited.
2, continue
The continue statement ends the loop in the most special way, because it does not really exit the loop, but only ends the execution of the loop body.
In the For loop, the expression 1 is executed first (note that expression 1 executes only once in the entire loop), then the expression 2 is executed, and if the condition is met, the loop body is executed, and if the continue statement is executed in the loop body, it jumps to the expression 3 and executes the next loop. Execute expression 2 to see if the condition is met;
In the while loop, if the continue statement is executed, it jumps directly to the expression and begins the Next loop judgment;
If the continue statement is executed in the Do While loop body, it jumps to the next loop judgment at the expression.
3. Return
If you encounter a return statement in a program, exit the function's execution, return to the function's call, and, if it is the main () function, end the entire program run. If executed in a custom function, then return to the function's call to continue execution after the return is executed.
4. Exit ()
The most important difference between the exit () function and the return statement is that calling the exit () function will end the current process while deleting the memory space occupied by the child process and passing the return information to the parent process. When the argument in exit () is 0 o'clock, indicating normal exit, the other return value indicates an abnormal exit, the exit () function means that the process is finished, and return represents the return of the call stack, which returns the function value and exits the currently executing function body, returning to the function's call, in main ( ) function, return n and exit (n) are equivalent.
The difference between Break,continue,return and exit