3 ms·
I got a silly question: Is this statement basically a do while/while(true) infinite loop? for (;;) { ... }
by ghrifter 11y ago
I got a silly question:
Is this statement basically a do while/while(true) infinite loop?
for (;;) {
...
}
- geocar 11y agoYes. 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.
- ghrifter 11y agoCool, 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 https://matt.sh/howto-c
- frik 11y agofor (;;) { ... } 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).
- niccaluim 11y agoAlso it looks like a spider. That's why I use it, anyway.
- fra 11y agoYes, it's an infinite loop.