Re: returning back to loop check condition without completing the loop
- From: ashish128 <ashish128@xxxxxxxxx>
- Date: Wed, 2 Apr 2008 23:51:44 -0700 (PDT)
On Mar 31, 8:00 pm, "Rick Rothstein \(MVP - VB\)"
<rick.newsNO.S...@xxxxxxxxxxxxxxxxxx> wrote:
I apologise if this question has been posted before but to be true,
I could not find it. I have a very little question. Please see below
Do While some_condition = TRUE
'-----Some Code----
If this_condition = TRUE then
' Here I would like to send the execution back to "Do
While some_condition = TRUE"
' and bypass all succeeding lines of code
End If
'-----Some Code----
loop
Kindly let me know if this is supported / possible in VBA.
You could use a Label Statement and a GoTo statement like this...
Do While some_condition = TRUE
'-----Some Code----
If this_condition = TRUE then GoTo Continue
'-----Some Code----
Continue:
Loop
Dear Rick,
Yes, now I can see your post (But still my post says 8 Messages
and I am ble to see only 6).
Thanks for the suggestion. Being a programmer (in C Language)
I was taught not to use "Goto" as a primary rule.
But if you are suggesting this then there must be no ther way.
Thank you again for showing the way.
It is not that GoTo should never be used; it's just that it should not be
misused. In order to duplicate the "Continue" statement that other languages
have, the construction I used is pretty much it. Now, it should only be used
when you are going to have multiple points within your loop where you will
want to skip to the next loop iteration from. For the simple construction
you gave, I would just use an If-Then housing to perform the "skip". Using
the structure of your originally posted code, something like this could be
used to skip to the next loop iteration...
Do While some_condition = TRUE
'-----Some Code----
If this_condition = FALSE Then
'-----Some Code----
End If
Loop
But, as I said, this is a simple construction. As you add more and more
points to "Continue" from, the nesting of the various "Continue points" can
get quite messy quite quickly; and the inverted logical tests in the various
If-Then statements to implement it can get harder and harder to follow if
you ever have to come back to the loop to modify it at some future date. The
GoTo solution I posted earlier simplifies the overall construction while
allowing you to keep your logical If-Then tests in the way you would
naturally think of them.
Rick- Hide quoted text -
- Show quoted text -
Dear Rick,
I agree to the points.
I will be using "Goto" only where no other logical flow exists.
Thanks again for your great help
Regards
.
- Prev by Date: Re: returning back to loop check condition without completing the loop
- Next by Date: RE: question regarding external data range
- Previous by thread: Re: returning back to loop check condition without completing the loop
- Next by thread: Which formula to use?
- Index(es):
Relevant Pages
|