Re: how do people feel about exit function from loop



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 -1
if SomeFunction(i) = "" then exit for
Next
I've made a couple of changes and the second is half the lines of code as
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


.



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)