Re: how do people feel about exit function from loop



"Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:uvKyVNmzHHA.3448@xxxxxxxxxxxxxxxxxxxxxxx
In some cases, though, you'll want variables altered inside the loop to be
in a known state on exiting the loop (for example, you know you want to be
at the end of a file, but also to flag a specific location/record within
it) and, as others have mentioned, to know HOW you hit the end of the
loop. Exit For and similar constructs become largely undesirable, involve
more coding and/or are less intuitive in cases like these.

Granted, cleanup code will be more likely to happen identically regardless
of how you exited the loop, but it's not guaranteed, depending on the
structure of your loop. If, for example, you're Setting an object to
something and then later to Nothing within the loop, the Exit For might
require a redundant Set to Nothing after the end of the loop.

What you're trying to do there is find situations that are suited to not
using exit for. Granted some cases might exist but 99.9% of loops are suited
to using exit for.

But it's all esoteric anyway. Who cares how you do your loops or why you
do or don't use Exit's, as long as your loops work as desired and are
reasonably easy to understand. Any advanced programmer should be able to
look at a loop and determine in about two seconds how it works, regardless
of which structure is being used. It's like writing haiku's versus
rhyming verse...they're both poetry, it's just a difference of style.

I care. If someone goes to extensive lengths to avoid using exit function or
exit for then the code becomes less readable. The example given by the OP
was significantly more difficult to read and it was a very simple loop. In
more complex loops it could become quite difficult to write and maintain and
there really is no benefit except to adhere to some self made preconception
of the programmer.

Michael


.



Relevant Pages

  • Re: Infinite Loops and Explicit Exits
    ... > CS> One of these proposals relaxes the current restriction that an EXIT ... > termination of the loop is not visible at that point. ... > terminating condition is visible in that context. ... > You now want to allow this remote procedure, ...
    (comp.lang.cobol)
  • Re: Houston-related rants was Re: forced merges/inside lane merges/AASHTO "tapered merges"
    ... >> Are you sure about the North Loop and I-45? ... >> in particular the westbound exit for Fondren/Gessner. ... How could HCTRA put an exit ramp for eastbound ... and the West Houston Center Blvd exit still shows Old Westheimer ...
    (misc.transport.road)
  • Re: Exit Do
    ... I've been instructed by a dot net / asp programmer that Exit Do is ... I am using nested loops and need to exit out of one loop into ... If Some Reason to stop loop then Exit Do ... Code Stage B ...
    (microsoft.public.scripting.vbscript)
  • Re: Exit Do
    ... I've been instructed by a dot net / asp programmer that Exit Do is ... I am using nested loops and need to exit out of one loop into ... Code Stage B ... likely to lead to bugs and readability problems. ...
    (microsoft.public.scripting.vbscript)
  • Re: Infinite Loops and Explicit Exits
    ... CS> There are cases in which EXIT PERFORM is, I think, clearer than GO TO ... procedure-name-1 SECTION. ... repetition in the main loop statement is being overrun by some minor ... particularly when the requirements of elegance ...
    (comp.lang.cobol)