for (::)

Started by
4 comments, last by Oluseyi 18 years, 7 months ago
What is that for?I haven't done any programming for 3 weeks and and I guess I forgot.
Advertisement
It's an ugly infinite loop that is used because people think it is clever. Should you need to write an infinite loop some day, which you shouldn't, prefer while(true) for at least some kind of clarity.
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
its also for(;;) not for(::)

for(;;) is logically equivalent to while(true)
moe.ron
Quote:Original post by xMcBaiNx
It's an ugly infinite loop that is used because people think it is clever. Should you need to write an infinite loop some day, which you shouldn't, prefer while(true) for at least some kind of clarity.

It's not an ugly way. It's the standard C and C++ way to do an infinite loop. That, and sometimes it's perfectly valid to create an infinite loop (with a breaking condition inside, of course).

I had a fealing you didn't press anything.Thanks I think while(TRUE) is better.But thanks anyway
Quote:Original post by xMcBaiNx
Should you need to write an infinite loop some day, which you shouldn't...

Rot. Infinite loops with breaking conditions are the proper way to handle, for instance, non-Win32 game/application main loops with multiple exit conditions.

Quote:Original post by Coder
It's not an ugly way. It's the standard C and C++ way to do an infinite loop.

That's unfortunate, as while (true) is semantically clearer. It is apparently implementation-defined whether the two constructs generate identical code, which is also unfortunate.

This topic is closed to new replies.

Advertisement