Re: Why is GOTO bad?
- From: "Michael C" <nospam@xxxxxxxxxx>
- Date: Fri, 18 Aug 2006 11:12:02 +1000
"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
.
- Follow-Ups:
- Re: Why is GOTO bad?
- From: Stephen Howe
- Re: Why is GOTO bad?
- References:
- Why is GOTO bad?
- From: Dale
- Re: Why is GOTO bad?
- From: Michael C
- Re: Why is GOTO bad?
- From: Stephen Howe
- Re: Why is GOTO bad?
- From: Michael C
- Re: Why is GOTO bad?
- From: Stephen Howe
- Why is GOTO bad?
- Prev by Date: Re: Resize form problem
- Next by Date: Re: Text on picture
- Previous by thread: Re: Why is GOTO bad?
- Next by thread: Re: Why is GOTO bad?
- Index(es):
Relevant Pages
|