# how would you make a for loop infinite?

• 10-16-2008
muzihc
how would you make a for loop infinite?
thank
• 10-16-2008
tabstop
If you think about it for 0.45 seconds, you'll figure out how to do it.

It will take a lot longer to figure out why you think you want to.
• 10-16-2008
mike_g
Code:

`for(;;)`
• 10-16-2008
Swarvy
Is there any advantage (I mean in terms of CPU efficiency etc) over doing:
Code:

`for(;;)`
Over something like:
Code:

`while(1)`
• 10-16-2008
tabstop
Since neither of them require any work, I'm pretty sure they would be exactly the same.
• 10-17-2008
EOP
Quote:

Originally Posted by tabstop
Since neither of them require any work, I'm pretty sure they would be exactly the same.

Sometimes guessing isn't enough. ;)

Code:

```for(;;); 0041298E  jmp        main+1Eh (41298Eh) while(1); 00412990  mov        eax,1 00412995  test        eax,eax 00412997  je          main+2Bh (41299Bh) 00412999  jmp        main+20h (412990h)```
• 10-17-2008
laserlight
Quote:

Originally Posted by EOP
Sometimes guessing isn't enough.

You probably did not enable optimisations, since modern compilers are smart enough to recognise that while(1) is an infinite loop and avoid evaluating its condition as a trivial optimisation.
• 10-17-2008
iMalc
Another way is to use a do ... while(1), and yet another way is to use that language construct starting with g that I shall not speak of.
I find that for(;;) is the best though because with certain compilers on high warning levels you can get a warning about a conditional expression being constant with the while's.
• 10-17-2008
master5001
You have to use two of those g statements if you wish to break out of that loop.
• 10-17-2008
Dino
Code:

```#include <stdio.h> int main () { label:                goto label ;         return 0; }```
• 10-17-2008
master5001
*gasp* He dare speak such treacherous words in the form of example!?
• 10-17-2008
Dino
Is this like Voldemort - aka, he whose name is not spoken?
• 10-17-2008
master5001
iMalc said he would not speak of goto statements by name, so I ran with it. Then your very next post was a goto example. So perhaps we can call you Gotomort?
• 10-17-2008
cpjust
Quote:

Originally Posted by iMalc
I find that for(;;) is the best though because with certain compilers on high warning levels you can get a warning about a conditional expression being constant with the while's.

It also saves 1 keystroke for those lazy people out there. ;)
• 10-18-2008
EOP
Quote:

Originally Posted by master5001
*gasp* He dare speak such treacherous words in the form of example!?

I know it's off topic, but here's an even more unspeakable command:

Quote:

COBOL Alter Verb

We now move on to the early COBOL ALTER verb that probably deserves the award for the worst programming language command.
http://www.gavilan.edu/csis/language...l#_Toc76036283

When I learned COBOL in the late 80's I asked my teacher if we may use alter in structured programming - he got almost a heart attack. :)