The Answer to Infinite Loops

Programmers, we should make our infinite loops more exciting! A lot of times in C or other languages, you see infinite loops represented by things such as

while (1) { /* do stuff here */ }

Or perhaps by

for (;;) { /* do stuff here */ }

Thats so boring! Why not be more creative in your work? I propose that we use the following construct instead

while (42) { /* do stuff here */ }

Now you might ask, why use while() instead of for() or do.. while()? In my opinion, its cleaner (the while part, not necessarily the number part). while() seems like the correct options, since (in my mind, at least) for() implies some set amount of iteration, whereas while() implies keep going until some condition is false. Of course, I do realize that they all do the same thing and each different one can do the same things as the others with some modification.

Yes, that was a rather useless post, but I had to get it off of my chest 🙂

3 Responses to “The Answer to Infinite Loops”

  1. nitro2k01 says:

    I agree that while is more clear than for, but why is while(42) more clear than while(1). yes, 42 is an important number which I have engraved on my towel, but while(42) is probably still likely to confuse the noobs. (As in “Why the heck”)
    It’s perfect for analogies though, like:
    while(42){live_life();}
    exit(0);

    or
    while(1337){keep_coding();}

    Or why not go a bit esoteric?
    for(i=0;–i;i++){ /* Do stuff */ }
    for(0;1;2){ /* Do stuff */ }

  2. dustin says:

    I edited the post a little bit, the while() part is cleaner, not the number part. And yes, it will probably confuse the n00bs, but they will learn an important lesson from it — 1 isn’t the only true number. :p

    Besides, this is mostly tongue-in-cheek 🙂

  3. Jon Anderson says:

    while(!0) is the best way to do it. 😛

    Otherwise !true != false

Leave a Reply