The ‘C’ test. Part – IV

Infinite loops
4. Infinite loops often arise in embedded systems. How does you code an infinite loop in C?

There are several solutions to this question. My preferred solution is:

while(1)
{
ý
}

Many programmers seem to prefer:

for(;;)
{
ý
}

This construct puzzles me because the syntax doesn’t exactly spell out what’s going on. Thus, if a candidate gives this as a solution, I’ll use it as an opportunity to explore their rationale for doing so. If their answer is basically, “I was taught to do it this way and I haven’t thought about it since,” it tells me something (bad) about them.

A third solution is to use a goto :

Loop:

goto Loop;

Candidates who propose this are either assembly language programmers (which is probably good), or else they are closet BASIC/FORTRAN programmers looking to get into a new field.

…to be continued