The difference between continue break return and continuebreak

Source: Internet
Author: User

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.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.