Re: while (1) vs. for ( ;; )



In article <kfnu0h78bb1.fsf@xxxxxxxxxxxxxxxxxxx>,
Tim Rentsch <txr@xxxxxxxxxxxxxxxxxxx> wrote:

> However, I don't believe that all "infinite-but-not-really"
> loops benefit from this kind of rewriting. Even for loops
> with only one exit condition, sometimes having the only loop
> exit be a break (or return) in the middle of the loop body
> is the clearest expression of what the loop is supposed to
> do. At least, that has been my experience.

Example:

for (;;) {

/* Quite a bit of code to find the next candidate */
if (no more candidates) break;

/* Check if this candidate can be ignored */
if (candidate can be ignored) continue;

/* Do the real work */
do_some_work ();
}

You can easily change this into "structured" code, but it doesn't
improve it.
.



Relevant Pages

  • Re: How to break a while loop inside a switch statement?
    ... have made worthless boolean variables to hold exit, fail, "error" or bad ... values simply as an exit condition for a nested loop. ...
    (comp.lang.java.programmer)
  • Strange Infinite Loop in My Code
    ... integers and store them in a 50 element array. ... My problem is that my loop won't exit. ... iterated, but is reset to 0 once the exit condition should be met, ...
    (comp.lang.cpp)
  • Re: How to break a while loop inside a switch statement?
    ... values simply as an exit condition for a nested loop. ... Nor do I use boolean flags to control loop exit conditions ...
    (comp.lang.java.programmer)
  • Re: while (1) vs. for ( ;; )
    ... >> loops benefit from this kind of rewriting. ... >> with only one exit condition, sometimes having the only loop ... Balmer Consulting ...
    (comp.lang.c)
  • Re: Input unknown number of integers in a line...
    ... To me, I would start with a while loop, as ... I just don't like to combine assignments ... doesn't emphasize the exit condition, as opposed to a loop which ... the broken "Reply" link at the bottom of the article. ...
    (comp.lang.c)