Break and continue, exit and return

Source: Internet
Author: User
Break and continue, exit and return -- Linux general technology-Linux programming and kernel information. The following is a detailed description. Finally, I fully understood these four functions!

Then we suddenly thought that there were two different keywords: return and exit.
Exit directly exits the program and will not be executed later
Return is only the return of the function. it will be executed later.
Exit () ends the current process/current program/. in the entire program, it ends when exit is called.
Return () is the return of the current function. of course, if it is in the main function, the current process is naturally ended. if it is not, it is returned to the previous layer for calling. If you want to check whether the process exits normally in multiple processes, you need to use the return value of the previous process ..
While exit (0) indicates that the program is normal, exit (1)/exit (-1) indicates that the program exits abnormally.



Both break and continue are used to jump out of the loop body, but one difference is that break is used to jump out of the whole loop and execute the next statement outside the loop body; continue only jumps out of this loop and continues to judge whether the next cycle condition is met.

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.