Hacker News new | ask | show | jobs
by ghrifter 3815 days ago
I got a silly question:

Is this statement basically a do while/while(true) infinite loop?

    for (;;) {
         ...
    }
2 comments

Yes. You're likely to run into this construct often in C.

Lots of people do it because stupid C compilers produce better code for `for(;;)` than they do for `while(1)` and stupid C compilers used to be very common.

It's also one less character spent: A rare win/win.

Also it looks like a spider. That's why I use it, anyway.
Cool, thanks! I have yet to learn C other than from what I've learned from programming in C++.

I am really interested in learning some C however, especially after this post hit front page a few days ago:

https://matt.sh/howto-c

  for (;;) { ... }
is a valid JavaScript and PHP syntax too. And used also as the first few chars of a JSON stream to prevent other sites consuming your internal API (e.g. Facebook uses it, Google+ uses while(1) { ... } which is longer).
Yes, it's an infinite loop.