Loading ...
Sorry, an error occurred while loading the content.

Re: [XP] How to code an infinite loop (was: What do you thinkabout these two coding idioms?)

Expand Messages
  • Kevin Smith
    ... Standard C idiom, but I ve never liked it. ... Personally, I generally use while(true), but some people hate that. ... Yuck. No advantage over (b), but
    Message 1 of 31 , Feb 26, 2001
    • 0 Attachment
      Dossy wrote:
      >Here's another style question. What do you prefer, for expressing
      >infinite loops:
      >
      >a) for (;;) { ... }

      Standard C idiom, but I've never liked it.

      >b) while (1) { ... }

      Personally, I generally use while(true), but some
      people hate that.

      >c) do { ... } while (1);

      Yuck. No advantage over (b), but more clutter.

      >d) start_infinite_loop:
      > ...
      > goto start_infinite_loop;

      YUCK.

      Kevin
    • azami@speakeasy.net
      ... lines I ... prefer ... Yes. I think someone is more likely to know that 1 evaluates to truth in C boolean expressions than they are to know that for(;;)
      Message 31 of 31 , Mar 1, 2001
      • 0 Attachment
        --- In extremeprogramming@y..., "Joshua Macy/Towers Perrin"
        > measures of readability. Justifications commonly run along the
        lines "I
        > have no trouble with X, but I worry that other people might, so I
        prefer
        > Y."

        Yes. I think someone is more likely to know that 1 evaluates to truth
        in C boolean expressions than they are to know that for(;;) loops
        infinitely. But if you use "TRUE" or "true" (define it as a const or
        macro if your language doesn't support it natively), your expression
        becomes very difficult to misunderstand - even for a programmer who's
        never seen C code before!
      Your message has been successfully submitted and would be delivered to recipients shortly.