[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.