ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Abort recursion (https://www.excelbanter.com/excel-programming/333094-abort-recursion.html)

Mike NG

Abort recursion
 
If I have a procedure which I call recursively. Is there a way I can say
exit all the way out completely. I know I could put logic and pass
flags up through the parameters etc. but just wondered if I could do
this another way

e.g a simple example

Sub Main ()
Hello (1)
End Sub

Sub Hello (x as Integer)
MsgBox x

if x < 10 then
Hello(x+1)
else
<some more processing
end if
end sub

It's a bit hard to explain cos the above is simple and what I am trying
to do is more complicated, but when the recursion reaches the end, I'd
like all the levels of Hello to unravel with no more execution taking
place
--
Mike

Tom Ogilvy

Abort recursion
 
Take out the <some more processing and your example does that - sounds like
you just have a design issue.

A stupid way would be to use the END statement.

--
regards,
Tom Ogilvy

"Mike NG" wrote in message
...
If I have a procedure which I call recursively. Is there a way I can say
exit all the way out completely. I know I could put logic and pass
flags up through the parameters etc. but just wondered if I could do
this another way

e.g a simple example

Sub Main ()
Hello (1)
End Sub

Sub Hello (x as Integer)
MsgBox x

if x < 10 then
Hello(x+1)
else
<some more processing
end if
end sub

It's a bit hard to explain cos the above is simple and what I am trying
to do is more complicated, but when the recursion reaches the end, I'd
like all the levels of Hello to unravel with no more execution taking
place
--
Mike




Mike NG

Abort recursion
 
On Tue, 28 Jun 2005 at 18:28:24, Tom Ogilvy (Tom Ogilvy
) wrote:
Take out the <some more processing and your example does that - sounds like
you just have a design issue.

A stupid way would be to use the END statement.

I'll have a little think. The <some more processing was actually
essential processing required before recursively calling Hello again -
so set up some variables which is the whole crux of the recursion in the
first place

Trouble is I am trying to fit someone else's code into my code and I've
been thinking about this for a while. Will have another go today. END
will not be an option as I don't want to stop execution all together
--
Mike


All times are GMT +1. The time now is 11:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com