[My solutions for the C language interview series] 003 endless loop format problem summary?

Source: Internet
Author: User
[My C language interview series] 003 Summary of the infinite loop format?

Summary of the infinite loop format

Below are several "Famous" Endless loops:

(1) endless operating system loops;

(2) Win32 program endless loop;

(3) endless loop of embedded system software;

(4) endless loop of thread processing functions of multi-threaded programs.

 

Sometimes we also need to use an endless loop in the program. Only when the conditions are met can the break exit the endless loop and continue the following code execution. There are two infinite loop solutions:

While (1)

{

......

}

For (;;)

{

......

}

The first format is often our preferred solution.

In the second format, because this syntax does not exactly express the meaning of the code, we can't see anything from for (;), only to understand (;;) in the C language, it means that the unconditional loop can understand its meaning. Some programmers write the second format as for (; 1;), which is even more confusing. We do not require everyone to unify all the code formats, but in this case, it is better to unify the code, because people who read your code will be more comfortable, it can enhance Code Communication Between programmers. The syntax of "dead-end" means that code writing is messy, and each of them has its own set. It is costly for code maintenance.

In C Programs, especially embedded programs, except for the main program's dead loop, it is generally recommended that you do not use the dead loop, because once your code has a slight error, this is what embedded people are most reluctant to see, because QA (Quality Testing Department) absolutely does not allow such programs to pass the test. However, sometimes we need to use an endless loop, depending on the actual situation.


 

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.