Infinite loops (a loop with an unconditionally true condition) are generally bad, and should be re-structured as potentially infinite loops. A well written server that relies on a loop as it's main form of receiving input should have a situation in which it's loop condition can be negated, thereby exitting the loop. This will allow for cleanup and shutdown of any periphery functions it's performing. A good example would be a simple HTTP server where the condition of the loop would be the output from a blocking socket, so if for whatever reason the socket is closed, it can clean up (i.e close log file handles) and possibly notify the administrator.

I can't think of any conditions in where you would need an infinitely running loop (any offers?) so I'd say that in theory they are a bad thing. It's also considered bad practice to have 'busy-wait loops'[1] when working with IO as you should generally be waiting for input to come instead of deliberately putting delays within the loop. One reason is that you *might* (just might) receive a shedload of data while sleeping away which could potentially break things within (and without) the program (i.e stack overflow).
HTH

_________
broquaint

[1] a busy-wait loop is one which has specified delays within the program e.g while(<FOO>) { &do_stuff($_); sleep 5; }. More details here


In reply to Re: infinite loops == bad? by broquaint
in thread infinite loops == bad? by BUU

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.