Is "for(;;)" faster than "while (TRUE)"? If not, why do people use it?

Chris Cooper picture Chris Cooper · Apr 10, 2010 · Viewed 41.4k times · Source
for (;;) {
    //Something to be done repeatedly
}

I have seen this sort of thing used a lot, but I think it is rather strange... Wouldn't it be much clearer to say while(true), or something along those lines?

I'm guessing that (as is the reason for many-a-programmer to resort to cryptic code) this is a tiny margin faster?

Why, and is it really worth it? If so, why not just define it this way:

#define while(true) for(;;)

See also: Which is faster: while(1) or while(2)?

Answer

Ben Zotto picture Ben Zotto · Apr 10, 2010
  1. It's not faster.
  2. If you really care, compile with assembler output for your platform and look to see.
  3. It doesn't matter. This never matters. Write your infinite loops however you like.