Re: how do people feel about exit function from loop
- From: "Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 29 Jul 2007 22:00:04 -0400
I don't think that is true at all. Unfortunately I'm a DB programmer as
well and almost every loop I do is appropriate for exit for (assuming it
needs to terminate early at all). I almost never encounter a loop that
needs a variable to exit. When I say almost never I reckon I could count
on 1 hand in 10+ years. If you think this is common I think you are
stetching the truth.
Obviously our programming styles or perhaps our needs are different, then.
For i = 100 to 1 Step -1I've made a couple of changes and the second is half the lines of code as
if SomeFunction(i) = "" then exit for
Next
the first. I don't see how this can be considered a bad thing. I don't see
how the second could not possibly be considered clearer.
Uhhh...yeah, but you've also change the nature of the loop, as the result is
no longer being assigned to strTest. The equivalent While loop would be...
i = 100
While (SomeFunction(i) <> "") And (i > 0)
i = i - 1
Wend
....which is hardly difficult to read.
Less code is still better when all else is equal.
SomeLoop: Debug.Print "Hello"
Goto SomeLoop
or
While True
Debug.Print "Hello"
Wend
or
For i = 1 To 2
i = i - 1
Debug.Print "Hello"
Next
All are obviously stupid ideas (especially the For loop in this case), and
yet the Goto loop requires the least amount of code. So why do we
discourage people from using that even in instances where it might make
perfect sense? It all comes back to style and how we were trained.
One (admittedly minor) advantage to using While loops is that you don't have
to drastically change your logic if you move to a language that doesn't
support Exit/Break/whatever.
Anyway, as I've said before, I'm not advocating my choices for anybody else.
It's how *I* think, and how *I* code, much like Rick thinks in one-liners
that the rest of us sit puzzling over for much longer than he does. Whether
you agree with them or not, the reasons I choose to continue to code that
way also make sense to me. Any and all arguments aside, though, I find it
much easier to code without the use of Exit For, and I'm generally proud at
the end of the day at the tidiness of my code. You code how you code, I
code how I code...end of story.
Rob
.
- Follow-Ups:
- Re: how do people feel about exit function from loop
- From: dNagel
- Re: how do people feel about exit function from loop
- From: Michael C
- Re: how do people feel about exit function from loop
- From: Michael C
- 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
- 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: Help for a VB prog
- 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
|