![]() |
returning back to loop check condition without completing the loop
Hi All,
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. Regards Ashish |
returning back to loop check condition without completing the loop
Do While some_condition = TRUE
'-----Some Code---- If this_condition = TRUE then 'do nothing else 'some code here End If 'no code here!!!! loop ashish128 wrote: Hi All, 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. Regards Ashish -- Dave Peterson |
returning back to loop check condition without completing the loop
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 Rick "ashish128" wrote in message ... Hi All, 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. Regards Ashish |
returning back to loop check condition without completing theloop
On Mar 18, 8:30*pm, Dave Peterson wrote:
Do While some_condition = TRUE * * * '-----Some Code---- * * * *If this_condition = TRUE then * * * * * *'do nothing * * * *else * * * * * *'some code here * * * *End If * * * *'no code here!!!! loop ashish128 wrote: Hi All, 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. Regards Ashish -- Dave Peterson- Hide quoted text - - Show quoted text - Hi Dave, I know this will work but I cannot do this. I just want to stop execution and return it to loop checking condition. Besides this, I need to apply this at several places in my loop. Thanks for your help |
returning back to loop check condition without completing theloop
On Mar 18, 8:30*pm, Dave Peterson wrote:
Do While some_condition = TRUE * * * '-----Some Code---- * * * *If this_condition = TRUE then * * * * * *'do nothing * * * *else * * * * * *'some code here * * * *End If * * * *'no code here!!!! loop ashish128 wrote: Hi All, 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. Regards Ashish -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, My question is to break the process flow in middle of a loop and restart it from the loop condition checking. Regards |
returning back to loop check condition without completing the loop
You didn't like Rick's reply?
ashish128 wrote: On Mar 18, 8:30 pm, Dave Peterson wrote: Do While some_condition = TRUE '-----Some Code---- If this_condition = TRUE then 'do nothing else 'some code here End If 'no code here!!!! loop ashish128 wrote: Hi All, 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. Regards Ashish -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, My question is to break the process flow in middle of a loop and restart it from the loop condition checking. Regards -- Dave Peterson |
returning back to loop check condition without completing theloop
On Mar 24, 5:35*pm, Dave Peterson wrote:
You didn't like Rick's reply? ashish128 wrote: On Mar 18, 8:30 pm, Dave Peterson wrote: Do While some_condition = TRUE * * * '-----Some Code---- * * * *If this_condition = TRUE then * * * * * *'do nothing * * * *else * * * * * *'some code here * * * *End If * * * *'no code here!!!! loop ashish128 wrote: Hi All, 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. Regards Ashish -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, My question is to break the process flow in middle of a loop and restart it from the loop condition checking. Regards -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, I must say that there is some problem with the GUI. My post says 6 messages but I cannot view more than 4 (two mine and two of yours) Therefore I dont even know if Rick has suggested some solution. Please convey my apologies to Rick (If you can) as I cannot see a single post of his. Thank You. Regards |
returning back to loop check condition without completing the loop
Hoping that you will be able to see this response from me, here is what I
posted originally... 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 Please indicate if you can see this message. If Ashish doesn't respond in a reasonable time period, will someone be kind enough to copy and post it back to Ashish for me. Rick "ashish128" wrote in message ... On Mar 24, 5:35 pm, Dave Peterson wrote: You didn't like Rick's reply? ashish128 wrote: On Mar 18, 8:30 pm, Dave Peterson wrote: Do While some_condition = TRUE '-----Some Code---- If this_condition = TRUE then 'do nothing else 'some code here End If 'no code here!!!! loop ashish128 wrote: Hi All, 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. Regards Ashish -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, My question is to break the process flow in middle of a loop and restart it from the loop condition checking. Regards -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, I must say that there is some problem with the GUI. My post says 6 messages but I cannot view more than 4 (two mine and two of yours) Therefore I dont even know if Rick has suggested some solution. Please convey my apologies to Rick (If you can) as I cannot see a single post of his. Thank You. Regards |
returning back to loop check condition without completing theloop
On Mar 31, 12:59*pm, "Rick Rothstein \(MVP - VB\)"
wrote: Hoping that you will be able to see this response from me, here is what I posted originally... 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 Please indicate if you can see this message. If Ashish doesn't respond in a reasonable time period, will someone be kind enough to copy and post it back to Ashish for me. Rick "ashish128" wrote in message ... On Mar 24, 5:35 pm, Dave Peterson wrote: You didn't like Rick's reply? ashish128 wrote: On Mar 18, 8:30 pm, Dave Peterson wrote: Do While some_condition = TRUE '-----Some Code---- If this_condition = TRUE then 'do nothing else 'some code here End If 'no code here!!!! loop ashish128 wrote: Hi All, 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. Regards Ashish -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, My question is to break the process flow in middle of a loop and restart it from the loop condition checking. Regards -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, I must say that there is some problem with the GUI. My post says 6 messages but I cannot view more than 4 (two mine and two of yours) Therefore I dont even know if Rick has suggested some solution. Please convey my apologies to Rick (If you can) as I cannot see a single post of his. Thank You. Regards- Hide quoted text - - Show quoted text - 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. Regards |
returning back to loop check condition without completing the loop
Why not use the "nested if" if you don't like GoTo's?
ashish128 wrote: On Mar 31, 12:59 pm, "Rick Rothstein \(MVP - VB\)" wrote: Hoping that you will be able to see this response from me, here is what I posted originally... 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 Please indicate if you can see this message. If Ashish doesn't respond in a reasonable time period, will someone be kind enough to copy and post it back to Ashish for me. Rick "ashish128" wrote in message ... On Mar 24, 5:35 pm, Dave Peterson wrote: You didn't like Rick's reply? ashish128 wrote: On Mar 18, 8:30 pm, Dave Peterson wrote: Do While some_condition = TRUE '-----Some Code---- If this_condition = TRUE then 'do nothing else 'some code here End If 'no code here!!!! loop ashish128 wrote: Hi All, 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. Regards Ashish -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, My question is to break the process flow in middle of a loop and restart it from the loop condition checking. Regards -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, I must say that there is some problem with the GUI. My post says 6 messages but I cannot view more than 4 (two mine and two of yours) Therefore I dont even know if Rick has suggested some solution. Please convey my apologies to Rick (If you can) as I cannot see a single post of his. Thank You. Regards- Hide quoted text - - Show quoted text - 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. Regards -- Dave Peterson |
returning back to loop check condition without completing the loop
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 |
returning back to loop check condition without completing theloop
On Mar 31, 7:36*pm, Dave Peterson wrote:
Why not use the "nested if" if you don't like GoTo's? ashish128 wrote: On Mar 31, 12:59 pm, "Rick Rothstein \(MVP - VB\)" wrote: Hoping that you will be able to see this response from me, here is what I posted originally... 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 Please indicate if you can see this message. If Ashish doesn't respond in a reasonable time period, will someone be kind enough to copy and post it back to Ashish for me. Rick "ashish128" wrote in message .... On Mar 24, 5:35 pm, Dave Peterson wrote: You didn't like Rick's reply? ashish128 wrote: On Mar 18, 8:30 pm, Dave Peterson wrote: Do While some_condition = TRUE '-----Some Code---- If this_condition = TRUE then 'do nothing else 'some code here End If 'no code here!!!! loop ashish128 wrote: Hi All, 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. Regards Ashish -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, My question is to break the process flow in middle of a loop and restart it from the loop condition checking. Regards -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, I must say that there is some problem with the GUI. My post says 6 messages but I cannot view more than 4 (two mine and two of yours) Therefore I dont even know if Rick has suggested some solution. Please convey my apologies to Rick (If you can) as I cannot see a single post of his. Thank You. Regards- Hide quoted text - - Show quoted text - 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. Regards -- Dave Peterson- Hide quoted text - - Show quoted text - Dear Dave, To be true, I didn't use "nested if" because I was preferring a clean solution as otherwise it would cause me to have (many if and) deep look into my code for any alteration if I break the loop at many points. Second truth, It didnt came to my mind :) I am applying Rick's suggestion to get the code work as intended. Thanks for your guidance (If it had not been you pointing to Rick's Post I would have never come to know about it) Regards |
returning back to loop check condition without completing theloop
On Mar 31, 8:00*pm, "Rick Rothstein \(MVP - VB\)"
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 |
returning back to loop check condition without completing the loop
If the code starts looking too bad, you could always call subroutines from
either branch of your if/then/else statement. And do all the detail work there. ashish128 wrote: <<snipped Dear Dave, To be true, I didn't use "nested if" because I was preferring a clean solution as otherwise it would cause me to have (many if and) deep look into my code for any alteration if I break the loop at many points. Second truth, It didnt came to my mind :) I am applying Rick's suggestion to get the code work as intended. Thanks for your guidance (If it had not been you pointing to Rick's Post I would have never come to know about it) Regards -- Dave Peterson |
All times are GMT +1. The time now is 06:17 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com