Re: how do people feel about exit function from loop

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Michael C" <nospam@xxxxxxxxxx> wrote in message
news:eTstCwkzHHA.4916@xxxxxxxxxxxxxxxxxxxxxxx
"Steve Gerrard" <mynamehere@xxxxxxxxxxx> wrote in message
news:js2dnQMV9MvgizvbnZ2dnUVZ_sOrnZ2d@xxxxxxxxxxxxxx
Indeed, I find more and more that I like to declare a boolean expressly for
the purpose of controlling a loop, such as Found or Done. It makes the code
completely clear, it is easy to adjust the conditions where the flag gets
set, and it is useful following the loop for deciding what to do next.
While Not Done
always makes perfect sense to me as a loop control.

Isn't an exit for that much simpler tho? You still get to have one way out of
a function if that is important to you (in 99% of functions it is not).


I am not opposed to exit for, in fact I quite like Larry's solution to the OP's
task. But I often find that after the loop, I need to know why it ended - found
the thingy, or ran out of places to look. I am now jaded enough to believe that
even if I don't need it today, and can't see how I ever would, eventually I will
need to know it for some reason, so might as well set it up that way. Sigh.


.



Relevant Pages

  • Re: two questions about thread
    ... The best way to do this is by using a flag or event that the child-threads ... monitor each loop. ... flag is set, they exit themselves. ... > the lock is ever released. ...
    (comp.lang.python)
  • Re: Break a loop with a button
    ... I would have the button set a flag and the loop check for the flag. ... and then exit in a controlled means. ... Time hit to the loop will only be the if statement that checks the flag. ... No windows calls and all of the overhead for that. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Break a loop with a button
    ... I would have the button set a flag and the loop check for the flag. ... and then exit in a controlled means. ... Time hit to the loop will only be the if statement that checks the flag. ... No windows calls and all of the overhead for that. ...
    (alt.comp.lang.borland-delphi)
  • Re: R> DROP in GForth
    ... complex control flow structure. ... that causes you to exit the loop. ... It provides a single exit. ... that leave immediately if the flag is true, ...
    (comp.lang.forth)
  • Re: two questions about thread
    ... monitor each loop. ... The parent thread only has to set the flag to cause the children to die. ... some threads may be blocked waiting for others to release them. ... The unblocked threads check the flag and exit, so they're never signal the blocked ones. ...
    (comp.lang.python)