The difference between continue break return and continuebreak
1. Functions of the continue statement
Terminate the execution of this loop, that is, the statement that has not been executed after the continue statement in the current loop is skipped, and then judge the next loop condition. 2. roles of the break statement (1) when the break is in the loop body, the execution of the entire loop is forcibly terminated, that is, the entire loop process is ended, and the condition for executing the loop is no longer determined, directly switch to the statement under the loop body. (2) When the break appears in the switch statement body of the loop body, it only jumps out of the switch statement body. 3. Function of the return Statement (1) Exit the return statement from the current method, return to the statement that calls the method, and continue to run down. (2) return returns a value to the statement that calls the method. The data type of the returned value must be the same as the type of the returned value in the method declaration. (3) return can also be followed by no parameter. If no parameter is included, return NULL. In fact, the main purpose is to interrupt function execution and return the call function.
Examples
1 #include <stdio.h> 2 int main() 3 { 4 int i = 5,n = 0; 5 while(i--) 6 { 7 if(i == 3) 8 // return; 9 // break;10 continue;11 else if(i == 1)12 n = 6;13 }14 n = n + 5;15 printf("i=%d\n",i);16 printf("n=%d\n",n);17 return 0; 18 }
When running continue, the result is:
1 i=-12 n=11
When break is run, the result is:
1 i=32 i=5
When return is run, no result is returned. It means that when I = 3 is executed, the main function has been taken out and the following statement is not executed.