Re: how do people feel about exit function from loop
- From: dNagel <NOTGrandNagel@xxxxxxxxxxx>
- Date: Sun, 29 Jul 2007 23:31:05 -0700
Robert Morley wrote:
You know, I think you've gotten to the heart of why I don't like Exit For and similar constructs, never mind that structured programming says you shouldn't use them. Imagine a complex loop rendered into English:The problem with the first approach is that there are more than one exit from the routine, which means
For w. Exits
"For each of these items, I want you to do some things to them. Except if you run across this. Oh, and also stop if you find something else. Or if you run into any problems."
While/Until/etc.
"Unless you run across this, find something else, or run into any problems, do some things to each of these items."
Now, you might argue that the change in sentence structure makes the first appear more disruptive, but in truth, when I look at most Exit For conditions, that's *exactly* how I perceive them...something unexpected when you thought you were going to flow smoothly. When I see a While loop, I know that there are conditions to be fulfilled, can examine them all at once, then find out what I do as long as those conditions aren't fulfilled.
the reader has to examine the whole routine for exceptions to the control logic before they can examine
the data operations. Keeping loop code to a single entry and exit point makes sense and should be the
preferred method of implementation. If a routine has this many exceptions it should probably be
re-factored.
Heres a great series of questions to ask yourself when writing loops...
http://www.cc2e.com/Page.aspx?hid=233
D.
.
- Follow-Ups:
- Re: how do people feel about exit function from loop
- From: dNagel
- Re: how do people feel about exit function from loop
- References:
- how do people feel about exit function from loop
- From: greg
- Re: how do people feel about exit function from loop
- From: Ken Halter
- Re: how do people feel about exit function from loop
- From: Jan Hyde (VB MVP)
- Re: how do people feel about exit function from loop
- From: Steve Gerrard
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Robert Morley
- Re: how do people feel about exit function from loop
- From: dNagel
- Re: how do people feel about exit function from loop
- From: Robert Morley
- how do people feel about exit function from loop
- Prev by Date: Re: how do people feel about exit function from loop
- Next by Date: Re: How to kill a keystroke in listbox
- Previous by thread: Re: how do people feel about exit function from loop
- Next by thread: Re: how do people feel about exit function from loop
- Index(es):
Relevant Pages
|