Re: Exit Do
- From: "ekkehard.horner" <ekkehard.horner@xxxxxxxx>
- Date: Sat, 22 Mar 2008 14:36:11 +0100
Robbie Flower schrieb:
Ask him/her to define "great way".
I've been instructed by a dot net / asp programmer that Exit Do is not a great way to end a loop.
Can someone explain to me if this is so, or does this only apply to higher level programming languages ?Code in *all* languages should be easy to understand and not relying
on tricks/surprises.
I am using nested loops and need to exit out of one loop into another for something to apply. Any other functional ways of doing this ?A loop should terminate on a clearly defined condition:
Do Until oTS.AtEndOfStream
sLine = oTS.ReadLine
... process sLine ...
Loop
oTS.Close
To handle special a special case by "Exit Do"
Do Until oTS.AtEndOfStream
sLine = oTS.ReadLine
... process sLine ...
If "no more interesting stuff" = sLine
Exit Do
End If
Loop
oTS.Close
looks ok to me, but you can use an extra variable instead:
bAbort = False
Do Until oTS.AtEndOfStream Or bAbort
...
If "no more interesting stuff" = sLine
bAbort = True
End If
Loop
oTS.Close
I think that this is more complicated (3 places to think about
bAbort and 1 Or to take into account), but YMMV.
If you use Exit Do/For/Sub/Function, you should be aware that
'jumping to the right place' in deeply nested constructs may
not be possible (no labels in VBScript).
.
- Follow-Ups:
- Re: Exit Do
- From: Robbie Flower
- Re: Exit Do
- References:
- Exit Do
- From: Robbie Flower
- Exit Do
- Prev by Date: Re: Exit Do
- Next by Date: Re: InputBox output detection
- Previous by thread: Re: Exit Do
- Next by thread: Re: Exit Do
- Index(es):