Re: Why is GOTO bad?

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



"Stephen Howe" <sjhoweATdialDOTpipexDOTcom> wrote in message
news:%23XQ%23I8lwGHA.4576@xxxxxxxxxxxxxxxxxxxxxxx
My ideal language would be pretty close to a mixture of C's & BASIC's
contructs.
I prefer BASIC's EXIT DO rather than BREAK as that means you can do

FOR I = 1 TO N
DO
IF someCondition THEN EXIT FOR
LOOP
NEXT

I disagree with that. In this case it works for you just because you happen
to be using 2 different types of loop. If you had 2 for loops then it
wouldn't work. Ideally there should be some way to optionally label a loop
and have a "break label" statement. break on it's own would break just the
current loop.

but now I have repeated the same block of clean up code which I prefer not
to do.

A Try, Finally block would achieve what you need there. For VB I would think
wrapping it in a function would be the cleanest solution. I quite often use
this approach anyway to make things cleaner, especially if DoWhatever has a
large number of lines of code.

Sub DoSomething
'add appropriate error handling to ensure cleanup gets called.
AllocateResources
DoWhatever
CleanupResources
End sub

Sub DoWhatever
..... lot of lines of code here
End Sub

Michael


.



Relevant Pages

  • Re: killing a sub from within an if statement
    ... I see where you are denying the loop after it's run ... > terminate any objects through normal execution. ... You don't just exit the sub. ...
    (microsoft.public.excel.programming)
  • Re: Bash traps - while emitting ERR trap
    ... >> trap cleanup EXIT ERR ... >> while loop. ...
    (comp.unix.shell)
  • Re: `next LABEL usage
    ... Wants to exit a while loop inside a File::Find \&wanted sub routine. ... Is exiting the while loop sufficient.. ...
    (perl.beginners)
  • Re: Counting columns
    ... and use On Error to either exit the sub or exit the loop. ... > Dim Path, header As String ...
    (microsoft.public.project.vba)
  • RE: `next LABEL usage
    ... :> Harry Putnam wrote: ... : sub routine. ... Is exiting the while loop sufficient.. ... does one need to exit from the current file being offered ...
    (perl.beginners)