Need to break out of recursive function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Borg

    Need to break out of recursive function

    Hello,

    I call a function recursively to find an item that exists *anywhere* down
    the chain. Let's say I find it five layers deep. Now I've got what I need and
    want to break out of that whole stack and continue execution at the point of
    the initial call. Is that possible?

    Thanks,

    Bill
  • Imran Koradia

    #2
    Re: Need to break out of recursive function

    Do you mean skip the whole call stack? If that's the case, then AFAIK, you
    can't do that. You'll have to follow the call stack back to the point of the
    initial call. I believe the reason for this is the for each call to the
    recursive method, the current stack frame within the runtime stack has a
    pointer only to the previous stack frame from which this call was initiated
    and knows nothing about any stack frames before that. As soon as the current
    call returns, it returns to the address of the previous stack frame from
    which this call was made.

    hope that helps..
    Imran.

    "Bill Borg" <BillBorg@discu ssions.microsof t.com> wrote in message
    news:5E1333EA-DD0D-4FCD-BD06-E34C1610CEB1@mi crosoft.com...[color=blue]
    > Hello,
    >
    > I call a function recursively to find an item that exists *anywhere* down
    > the chain. Let's say I find it five layers deep. Now I've got what I need[/color]
    and[color=blue]
    > want to break out of that whole stack and continue execution at the point[/color]
    of[color=blue]
    > the initial call. Is that possible?
    >
    > Thanks,
    >
    > Bill[/color]


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: Need to break out of recursive function

      Bill,
      Normally I have the function return a "found" indicator (a Boolean), when I
      call it recursively if I find the item I exit the current item.

      Something like
      Public Function RecusiveFind(va lue As Object, theCurrentLevel ) As
      Boolean
      For Each item In theCurrentLevel
      If item = value Then Return True
      If RecusiveFind(va lue, item.Children) Then Return True
      ' keep looking at the current level
      Next
      Return False
      End Function


      "Bill Borg" <BillBorg@discu ssions.microsof t.com> wrote in message
      news:5E1333EA-DD0D-4FCD-BD06-E34C1610CEB1@mi crosoft.com...[color=blue]
      > Hello,
      >
      > I call a function recursively to find an item that exists *anywhere* down
      > the chain. Let's say I find it five layers deep. Now I've got what I need
      > and
      > want to break out of that whole stack and continue execution at the point
      > of
      > the initial call. Is that possible?
      >
      > Thanks,
      >
      > Bill[/color]


      Comment

      • Ken Dopierala Jr.

        #4
        Re: Need to break out of recursive function

        Hi Imran,

        You can add a global variable. Set it equal to False. Once you hit your
        finish point set it to True and Exit Function. Then in the function,
        directly after where it calls itself check this variable. If it is True
        then Exit Function which will move you right back up the stack and out.
        I've never tried using a static variable. I have no idea if that would
        work, hmmmm I'll have to try it. Good luck! Ken.

        --
        Ken Dopierala Jr.
        For great ASP.Net web hosting try:
        Small business web hosting offering additional business services such as: domain name registrations, email accounts, web services, online community resources and various small business solutions.

        If you sign up under me and have problems, email me.

        "Imran Koradia" <nospam@microso ft.com> wrote in message
        news:Og0cGsypEH A.536@TK2MSFTNG P09.phx.gbl...[color=blue]
        > Do you mean skip the whole call stack? If that's the case, then AFAIK, you
        > can't do that. You'll have to follow the call stack back to the point of[/color]
        the[color=blue]
        > initial call. I believe the reason for this is the for each call to the
        > recursive method, the current stack frame within the runtime stack has a
        > pointer only to the previous stack frame from which this call was[/color]
        initiated[color=blue]
        > and knows nothing about any stack frames before that. As soon as the[/color]
        current[color=blue]
        > call returns, it returns to the address of the previous stack frame from
        > which this call was made.
        >
        > hope that helps..
        > Imran.
        >
        > "Bill Borg" <BillBorg@discu ssions.microsof t.com> wrote in message
        > news:5E1333EA-DD0D-4FCD-BD06-E34C1610CEB1@mi crosoft.com...[color=green]
        > > Hello,
        > >
        > > I call a function recursively to find an item that exists *anywhere*[/color][/color]
        down[color=blue][color=green]
        > > the chain. Let's say I find it five layers deep. Now I've got what I[/color][/color]
        need[color=blue]
        > and[color=green]
        > > want to break out of that whole stack and continue execution at the[/color][/color]
        point[color=blue]
        > of[color=green]
        > > the initial call. Is that possible?
        > >
        > > Thanks,
        > >
        > > Bill[/color]
        >
        >[/color]


        Comment

        • Greg Burns

          #5
          Re: Need to break out of recursive function

          Why a global variable? Couldn't you just pass your boolean variable as one
          of the parameters of the recursive function. In fact, isn't this how you
          create a recursive function???

          Greg

          "Ken Dopierala Jr." <kdopierala2@wi .rr.com> wrote in message
          news:%23xsDNKzp EHA.4004@TK2MSF TNGP10.phx.gbl. ..[color=blue]
          > Hi Imran,
          >
          > You can add a global variable. Set it equal to False. Once you hit your
          > finish point set it to True and Exit Function. Then in the function,
          > directly after where it calls itself check this variable. If it is True
          > then Exit Function which will move you right back up the stack and out.
          > I've never tried using a static variable. I have no idea if that would
          > work, hmmmm I'll have to try it. Good luck! Ken.
          >
          > --
          > Ken Dopierala Jr.
          > For great ASP.Net web hosting try:
          > http://www.webhost4life.com/default.asp?refid=Spinlight
          > If you sign up under me and have problems, email me.
          >
          > "Imran Koradia" <nospam@microso ft.com> wrote in message
          > news:Og0cGsypEH A.536@TK2MSFTNG P09.phx.gbl...[color=green]
          >> Do you mean skip the whole call stack? If that's the case, then AFAIK,
          >> you
          >> can't do that. You'll have to follow the call stack back to the point of[/color]
          > the[color=green]
          >> initial call. I believe the reason for this is the for each call to the
          >> recursive method, the current stack frame within the runtime stack has a
          >> pointer only to the previous stack frame from which this call was[/color]
          > initiated[color=green]
          >> and knows nothing about any stack frames before that. As soon as the[/color]
          > current[color=green]
          >> call returns, it returns to the address of the previous stack frame from
          >> which this call was made.
          >>
          >> hope that helps..
          >> Imran.
          >>
          >> "Bill Borg" <BillBorg@discu ssions.microsof t.com> wrote in message
          >> news:5E1333EA-DD0D-4FCD-BD06-E34C1610CEB1@mi crosoft.com...[color=darkred]
          >> > Hello,
          >> >
          >> > I call a function recursively to find an item that exists *anywhere*[/color][/color]
          > down[color=green][color=darkred]
          >> > the chain. Let's say I find it five layers deep. Now I've got what I[/color][/color]
          > need[color=green]
          >> and[color=darkred]
          >> > want to break out of that whole stack and continue execution at the[/color][/color]
          > point[color=green]
          >> of[color=darkred]
          >> > the initial call. Is that possible?
          >> >
          >> > Thanks,
          >> >
          >> > Bill[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • Imran Koradia

            #6
            Re: Need to break out of recursive function

            Right - I understand that. But you're still going to be checking that
            variable for each recursive call that you made. Ofcourse, you can avoid the
            code after the recursive call within the method. But you're still going to
            pass through the entire call stack back to the initial call. There's no way
            you can skip the call stack. Or am I missing something?

            Imran.

            "Ken Dopierala Jr." <kdopierala2@wi .rr.com> wrote in message
            news:%23xsDNKzp EHA.4004@TK2MSF TNGP10.phx.gbl. ..[color=blue]
            > Hi Imran,
            >
            > You can add a global variable. Set it equal to False. Once you hit your
            > finish point set it to True and Exit Function. Then in the function,
            > directly after where it calls itself check this variable. If it is True
            > then Exit Function which will move you right back up the stack and out.
            > I've never tried using a static variable. I have no idea if that would
            > work, hmmmm I'll have to try it. Good luck! Ken.
            >
            > --
            > Ken Dopierala Jr.
            > For great ASP.Net web hosting try:
            > http://www.webhost4life.com/default.asp?refid=Spinlight
            > If you sign up under me and have problems, email me.
            >
            > "Imran Koradia" <nospam@microso ft.com> wrote in message
            > news:Og0cGsypEH A.536@TK2MSFTNG P09.phx.gbl...[color=green]
            > > Do you mean skip the whole call stack? If that's the case, then AFAIK,[/color][/color]
            you[color=blue][color=green]
            > > can't do that. You'll have to follow the call stack back to the point of[/color]
            > the[color=green]
            > > initial call. I believe the reason for this is the for each call to the
            > > recursive method, the current stack frame within the runtime stack has a
            > > pointer only to the previous stack frame from which this call was[/color]
            > initiated[color=green]
            > > and knows nothing about any stack frames before that. As soon as the[/color]
            > current[color=green]
            > > call returns, it returns to the address of the previous stack frame from
            > > which this call was made.
            > >
            > > hope that helps..
            > > Imran.
            > >
            > > "Bill Borg" <BillBorg@discu ssions.microsof t.com> wrote in message
            > > news:5E1333EA-DD0D-4FCD-BD06-E34C1610CEB1@mi crosoft.com...[color=darkred]
            > > > Hello,
            > > >
            > > > I call a function recursively to find an item that exists *anywhere*[/color][/color]
            > down[color=green][color=darkred]
            > > > the chain. Let's say I find it five layers deep. Now I've got what I[/color][/color]
            > need[color=green]
            > > and[color=darkred]
            > > > want to break out of that whole stack and continue execution at the[/color][/color]
            > point[color=green]
            > > of[color=darkred]
            > > > the initial call. Is that possible?
            > > >
            > > > Thanks,
            > > >
            > > > Bill[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Guest's Avatar

              #7
              Re: Need to break out of recursive function

              You could kill the whole stack by throwing an exception :-)

              --
              Jonathan Bailey.

              "Imran Koradia" <nospam@microso ft.com> wrote in message
              news:eL%23gqOzp EHA.868@TK2MSFT NGP10.phx.gbl.. .[color=blue]
              > Right - I understand that. But you're still going to be checking that
              > variable for each recursive call that you made. Ofcourse, you can avoid[/color]
              the[color=blue]
              > code after the recursive call within the method. But you're still going to
              > pass through the entire call stack back to the initial call. There's no[/color]
              way[color=blue]
              > you can skip the call stack. Or am I missing something?
              >
              > Imran.
              >
              > "Ken Dopierala Jr." <kdopierala2@wi .rr.com> wrote in message
              > news:%23xsDNKzp EHA.4004@TK2MSF TNGP10.phx.gbl. ..[color=green]
              > > Hi Imran,
              > >
              > > You can add a global variable. Set it equal to False. Once you hit[/color][/color]
              your[color=blue][color=green]
              > > finish point set it to True and Exit Function. Then in the function,
              > > directly after where it calls itself check this variable. If it is True
              > > then Exit Function which will move you right back up the stack and out.
              > > I've never tried using a static variable. I have no idea if that would
              > > work, hmmmm I'll have to try it. Good luck! Ken.
              > >
              > > --
              > > Ken Dopierala Jr.
              > > For great ASP.Net web hosting try:
              > > http://www.webhost4life.com/default.asp?refid=Spinlight
              > > If you sign up under me and have problems, email me.
              > >
              > > "Imran Koradia" <nospam@microso ft.com> wrote in message
              > > news:Og0cGsypEH A.536@TK2MSFTNG P09.phx.gbl...[color=darkred]
              > > > Do you mean skip the whole call stack? If that's the case, then AFAIK,[/color][/color]
              > you[color=green][color=darkred]
              > > > can't do that. You'll have to follow the call stack back to the point[/color][/color][/color]
              of[color=blue][color=green]
              > > the[color=darkred]
              > > > initial call. I believe the reason for this is the for each call to[/color][/color][/color]
              the[color=blue][color=green][color=darkred]
              > > > recursive method, the current stack frame within the runtime stack has[/color][/color][/color]
              a[color=blue][color=green][color=darkred]
              > > > pointer only to the previous stack frame from which this call was[/color]
              > > initiated[color=darkred]
              > > > and knows nothing about any stack frames before that. As soon as the[/color]
              > > current[color=darkred]
              > > > call returns, it returns to the address of the previous stack frame[/color][/color][/color]
              from[color=blue][color=green][color=darkred]
              > > > which this call was made.
              > > >
              > > > hope that helps..
              > > > Imran.
              > > >
              > > > "Bill Borg" <BillBorg@discu ssions.microsof t.com> wrote in message
              > > > news:5E1333EA-DD0D-4FCD-BD06-E34C1610CEB1@mi crosoft.com...
              > > > > Hello,
              > > > >
              > > > > I call a function recursively to find an item that exists *anywhere*[/color]
              > > down[color=darkred]
              > > > > the chain. Let's say I find it five layers deep. Now I've got what I[/color]
              > > need[color=darkred]
              > > > and
              > > > > want to break out of that whole stack and continue execution at the[/color]
              > > point[color=darkred]
              > > > of
              > > > > the initial call. Is that possible?
              > > > >
              > > > > Thanks,
              > > > >
              > > > > Bill
              > > >
              > > >[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Imran Koradia

                #8
                Re: Need to break out of recursive function

                Well - even when an exception is thrown, the runtime searches up the call
                stack to look for an appropriate exception handler which means its still
                going to be travelling up the call stack. However, I'm not sure how the
                runtime handles exceptions for recursive procedures - is it even aware that
                its a recursive call? If so, it could just check once whether the procedure
                has an exception handler and if not, it could skip the entire stack sequence
                for the recursion and jump right back to the initial calling method. But I
                doubt that..I could be wrong though..

                Imran.

                <jb> wrote in message news:415d1ca8$0 $17289$afc38c87 @news.easynet.c o.uk...[color=blue]
                > You could kill the whole stack by throwing an exception :-)
                >
                > --
                > Jonathan Bailey.
                >
                > "Imran Koradia" <nospam@microso ft.com> wrote in message
                > news:eL%23gqOzp EHA.868@TK2MSFT NGP10.phx.gbl.. .[color=green]
                > > Right - I understand that. But you're still going to be checking that
                > > variable for each recursive call that you made. Ofcourse, you can avoid[/color]
                > the[color=green]
                > > code after the recursive call within the method. But you're still going[/color][/color]
                to[color=blue][color=green]
                > > pass through the entire call stack back to the initial call. There's no[/color]
                > way[color=green]
                > > you can skip the call stack. Or am I missing something?
                > >
                > > Imran.
                > >
                > > "Ken Dopierala Jr." <kdopierala2@wi .rr.com> wrote in message
                > > news:%23xsDNKzp EHA.4004@TK2MSF TNGP10.phx.gbl. ..[color=darkred]
                > > > Hi Imran,
                > > >
                > > > You can add a global variable. Set it equal to False. Once you hit[/color][/color]
                > your[color=green][color=darkred]
                > > > finish point set it to True and Exit Function. Then in the function,
                > > > directly after where it calls itself check this variable. If it is[/color][/color][/color]
                True[color=blue][color=green][color=darkred]
                > > > then Exit Function which will move you right back up the stack and[/color][/color][/color]
                out.[color=blue][color=green][color=darkred]
                > > > I've never tried using a static variable. I have no idea if that[/color][/color][/color]
                would[color=blue][color=green][color=darkred]
                > > > work, hmmmm I'll have to try it. Good luck! Ken.
                > > >
                > > > --
                > > > Ken Dopierala Jr.
                > > > For great ASP.Net web hosting try:
                > > > http://www.webhost4life.com/default.asp?refid=Spinlight
                > > > If you sign up under me and have problems, email me.
                > > >
                > > > "Imran Koradia" <nospam@microso ft.com> wrote in message
                > > > news:Og0cGsypEH A.536@TK2MSFTNG P09.phx.gbl...
                > > > > Do you mean skip the whole call stack? If that's the case, then[/color][/color][/color]
                AFAIK,[color=blue][color=green]
                > > you[color=darkred]
                > > > > can't do that. You'll have to follow the call stack back to the[/color][/color][/color]
                point[color=blue]
                > of[color=green][color=darkred]
                > > > the
                > > > > initial call. I believe the reason for this is the for each call to[/color][/color]
                > the[color=green][color=darkred]
                > > > > recursive method, the current stack frame within the runtime stack[/color][/color][/color]
                has[color=blue]
                > a[color=green][color=darkred]
                > > > > pointer only to the previous stack frame from which this call was
                > > > initiated
                > > > > and knows nothing about any stack frames before that. As soon as the
                > > > current
                > > > > call returns, it returns to the address of the previous stack frame[/color][/color]
                > from[color=green][color=darkred]
                > > > > which this call was made.
                > > > >
                > > > > hope that helps..
                > > > > Imran.
                > > > >
                > > > > "Bill Borg" <BillBorg@discu ssions.microsof t.com> wrote in message
                > > > > news:5E1333EA-DD0D-4FCD-BD06-E34C1610CEB1@mi crosoft.com...
                > > > > > Hello,
                > > > > >
                > > > > > I call a function recursively to find an item that exists[/color][/color][/color]
                *anywhere*[color=blue][color=green][color=darkred]
                > > > down
                > > > > > the chain. Let's say I find it five layers deep. Now I've got what[/color][/color][/color]
                I[color=blue][color=green][color=darkred]
                > > > need
                > > > > and
                > > > > > want to break out of that whole stack and continue execution at[/color][/color][/color]
                the[color=blue][color=green][color=darkred]
                > > > point
                > > > > of
                > > > > > the initial call. Is that possible?
                > > > > >
                > > > > > Thanks,
                > > > > >
                > > > > > Bill
                > > > >
                > > > >
                > > >
                > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • Guest's Avatar

                  #9
                  Re: Need to break out of recursive function

                  I was joking of course :-)
                  I cant find in the MS website where exceptions are defined but I expect vb
                  creates a try,catch block around any function which might throw one which
                  then passes it to the previous caller.
                  It just 'looks like' you are skipping up the stack in the source code.

                  --
                  Jonathan Bailey.

                  "Imran Koradia" <nospam@microso ft.com> wrote in message
                  news:%23BLo3h7p EHA.3988@tk2msf tngp13.phx.gbl. ..[color=blue]
                  > Well - even when an exception is thrown, the runtime searches up the call
                  > stack to look for an appropriate exception handler which means its still
                  > going to be travelling up the call stack. However, I'm not sure how the
                  > runtime handles exceptions for recursive procedures - is it even aware[/color]
                  that[color=blue]
                  > its a recursive call? If so, it could just check once whether the[/color]
                  procedure[color=blue]
                  > has an exception handler and if not, it could skip the entire stack[/color]
                  sequence[color=blue]
                  > for the recursion and jump right back to the initial calling method. But I
                  > doubt that..I could be wrong though..
                  >
                  > Imran.
                  >
                  > <jb> wrote in message news:415d1ca8$0 $17289$afc38c87 @news.easynet.c o.uk...[color=green]
                  > > You could kill the whole stack by throwing an exception :-)
                  > >
                  > > --
                  > > Jonathan Bailey.
                  > >
                  > > "Imran Koradia" <nospam@microso ft.com> wrote in message
                  > > news:eL%23gqOzp EHA.868@TK2MSFT NGP10.phx.gbl.. .[color=darkred]
                  > > > Right - I understand that. But you're still going to be checking that
                  > > > variable for each recursive call that you made. Ofcourse, you can[/color][/color][/color]
                  avoid[color=blue][color=green]
                  > > the[color=darkred]
                  > > > code after the recursive call within the method. But you're still[/color][/color][/color]
                  going[color=blue]
                  > to[color=green][color=darkred]
                  > > > pass through the entire call stack back to the initial call. There's[/color][/color][/color]
                  no[color=blue][color=green]
                  > > way[color=darkred]
                  > > > you can skip the call stack. Or am I missing something?
                  > > >
                  > > > Imran.
                  > > >
                  > > > "Ken Dopierala Jr." <kdopierala2@wi .rr.com> wrote in message
                  > > > news:%23xsDNKzp EHA.4004@TK2MSF TNGP10.phx.gbl. ..
                  > > > > Hi Imran,
                  > > > >
                  > > > > You can add a global variable. Set it equal to False. Once you hit[/color]
                  > > your[color=darkred]
                  > > > > finish point set it to True and Exit Function. Then in the[/color][/color][/color]
                  function,[color=blue][color=green][color=darkred]
                  > > > > directly after where it calls itself check this variable. If it is[/color][/color]
                  > True[color=green][color=darkred]
                  > > > > then Exit Function which will move you right back up the stack and[/color][/color]
                  > out.[color=green][color=darkred]
                  > > > > I've never tried using a static variable. I have no idea if that[/color][/color]
                  > would[color=green][color=darkred]
                  > > > > work, hmmmm I'll have to try it. Good luck! Ken.
                  > > > >
                  > > > > --
                  > > > > Ken Dopierala Jr.
                  > > > > For great ASP.Net web hosting try:
                  > > > > http://www.webhost4life.com/default.asp?refid=Spinlight
                  > > > > If you sign up under me and have problems, email me.
                  > > > >
                  > > > > "Imran Koradia" <nospam@microso ft.com> wrote in message
                  > > > > news:Og0cGsypEH A.536@TK2MSFTNG P09.phx.gbl...
                  > > > > > Do you mean skip the whole call stack? If that's the case, then[/color][/color]
                  > AFAIK,[color=green][color=darkred]
                  > > > you
                  > > > > > can't do that. You'll have to follow the call stack back to the[/color][/color]
                  > point[color=green]
                  > > of[color=darkred]
                  > > > > the
                  > > > > > initial call. I believe the reason for this is the for each call[/color][/color][/color]
                  to[color=blue][color=green]
                  > > the[color=darkred]
                  > > > > > recursive method, the current stack frame within the runtime stack[/color][/color]
                  > has[color=green]
                  > > a[color=darkred]
                  > > > > > pointer only to the previous stack frame from which this call was
                  > > > > initiated
                  > > > > > and knows nothing about any stack frames before that. As soon as[/color][/color][/color]
                  the[color=blue][color=green][color=darkred]
                  > > > > current
                  > > > > > call returns, it returns to the address of the previous stack[/color][/color][/color]
                  frame[color=blue][color=green]
                  > > from[color=darkred]
                  > > > > > which this call was made.
                  > > > > >
                  > > > > > hope that helps..
                  > > > > > Imran.
                  > > > > >
                  > > > > > "Bill Borg" <BillBorg@discu ssions.microsof t.com> wrote in message
                  > > > > > news:5E1333EA-DD0D-4FCD-BD06-E34C1610CEB1@mi crosoft.com...
                  > > > > > > Hello,
                  > > > > > >
                  > > > > > > I call a function recursively to find an item that exists[/color][/color]
                  > *anywhere*[color=green][color=darkred]
                  > > > > down
                  > > > > > > the chain. Let's say I find it five layers deep. Now I've got[/color][/color][/color]
                  what[color=blue]
                  > I[color=green][color=darkred]
                  > > > > need
                  > > > > > and
                  > > > > > > want to break out of that whole stack and continue execution at[/color][/color]
                  > the[color=green][color=darkred]
                  > > > > point
                  > > > > > of
                  > > > > > > the initial call. Is that possible?
                  > > > > > >
                  > > > > > > Thanks,
                  > > > > > >
                  > > > > > > Bill
                  > > > > >
                  > > > > >
                  > > > >
                  > > > >
                  > > >
                  > > >[/color]
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • Imran Koradia

                    #10
                    Re: Need to break out of recursive function

                    lol :)
                    yeah - I couldn't find anything either but considering how exception
                    handling works in java, I bet that's how it works.

                    Imran.

                    <jb> wrote in message news:415d6b55$0 $17366$afc38c87 @news.easynet.c o.uk...[color=blue]
                    > I was joking of course :-)
                    > I cant find in the MS website where exceptions are defined but I expect vb
                    > creates a try,catch block around any function which might throw one which
                    > then passes it to the previous caller.
                    > It just 'looks like' you are skipping up the stack in the source code.
                    >
                    > --
                    > Jonathan Bailey.
                    >
                    > "Imran Koradia" <nospam@microso ft.com> wrote in message
                    > news:%23BLo3h7p EHA.3988@tk2msf tngp13.phx.gbl. ..[color=green]
                    > > Well - even when an exception is thrown, the runtime searches up the[/color][/color]
                    call[color=blue][color=green]
                    > > stack to look for an appropriate exception handler which means its still
                    > > going to be travelling up the call stack. However, I'm not sure how the
                    > > runtime handles exceptions for recursive procedures - is it even aware[/color]
                    > that[color=green]
                    > > its a recursive call? If so, it could just check once whether the[/color]
                    > procedure[color=green]
                    > > has an exception handler and if not, it could skip the entire stack[/color]
                    > sequence[color=green]
                    > > for the recursion and jump right back to the initial calling method. But[/color][/color]
                    I[color=blue][color=green]
                    > > doubt that..I could be wrong though..
                    > >
                    > > Imran.
                    > >
                    > > <jb> wrote in message[/color][/color]
                    news:415d1ca8$0 $17289$afc38c87 @news.easynet.c o.uk...[color=blue][color=green][color=darkred]
                    > > > You could kill the whole stack by throwing an exception :-)
                    > > >
                    > > > --
                    > > > Jonathan Bailey.
                    > > >
                    > > > "Imran Koradia" <nospam@microso ft.com> wrote in message
                    > > > news:eL%23gqOzp EHA.868@TK2MSFT NGP10.phx.gbl.. .
                    > > > > Right - I understand that. But you're still going to be checking[/color][/color][/color]
                    that[color=blue][color=green][color=darkred]
                    > > > > variable for each recursive call that you made. Ofcourse, you can[/color][/color]
                    > avoid[color=green][color=darkred]
                    > > > the
                    > > > > code after the recursive call within the method. But you're still[/color][/color]
                    > going[color=green]
                    > > to[color=darkred]
                    > > > > pass through the entire call stack back to the initial call. There's[/color][/color]
                    > no[color=green][color=darkred]
                    > > > way
                    > > > > you can skip the call stack. Or am I missing something?
                    > > > >
                    > > > > Imran.
                    > > > >
                    > > > > "Ken Dopierala Jr." <kdopierala2@wi .rr.com> wrote in message
                    > > > > news:%23xsDNKzp EHA.4004@TK2MSF TNGP10.phx.gbl. ..
                    > > > > > Hi Imran,
                    > > > > >
                    > > > > > You can add a global variable. Set it equal to False. Once you[/color][/color][/color]
                    hit[color=blue][color=green][color=darkred]
                    > > > your
                    > > > > > finish point set it to True and Exit Function. Then in the[/color][/color]
                    > function,[color=green][color=darkred]
                    > > > > > directly after where it calls itself check this variable. If it[/color][/color][/color]
                    is[color=blue][color=green]
                    > > True[color=darkred]
                    > > > > > then Exit Function which will move you right back up the stack and[/color]
                    > > out.[color=darkred]
                    > > > > > I've never tried using a static variable. I have no idea if that[/color]
                    > > would[color=darkred]
                    > > > > > work, hmmmm I'll have to try it. Good luck! Ken.
                    > > > > >
                    > > > > > --
                    > > > > > Ken Dopierala Jr.
                    > > > > > For great ASP.Net web hosting try:
                    > > > > > http://www.webhost4life.com/default.asp?refid=Spinlight
                    > > > > > If you sign up under me and have problems, email me.
                    > > > > >
                    > > > > > "Imran Koradia" <nospam@microso ft.com> wrote in message
                    > > > > > news:Og0cGsypEH A.536@TK2MSFTNG P09.phx.gbl...
                    > > > > > > Do you mean skip the whole call stack? If that's the case, then[/color]
                    > > AFAIK,[color=darkred]
                    > > > > you
                    > > > > > > can't do that. You'll have to follow the call stack back to the[/color]
                    > > point[color=darkred]
                    > > > of
                    > > > > > the
                    > > > > > > initial call. I believe the reason for this is the for each call[/color][/color]
                    > to[color=green][color=darkred]
                    > > > the
                    > > > > > > recursive method, the current stack frame within the runtime[/color][/color][/color]
                    stack[color=blue][color=green]
                    > > has[color=darkred]
                    > > > a
                    > > > > > > pointer only to the previous stack frame from which this call[/color][/color][/color]
                    was[color=blue][color=green][color=darkred]
                    > > > > > initiated
                    > > > > > > and knows nothing about any stack frames before that. As soon as[/color][/color]
                    > the[color=green][color=darkred]
                    > > > > > current
                    > > > > > > call returns, it returns to the address of the previous stack[/color][/color]
                    > frame[color=green][color=darkred]
                    > > > from
                    > > > > > > which this call was made.
                    > > > > > >
                    > > > > > > hope that helps..
                    > > > > > > Imran.
                    > > > > > >
                    > > > > > > "Bill Borg" <BillBorg@discu ssions.microsof t.com> wrote in[/color][/color][/color]
                    message[color=blue][color=green][color=darkred]
                    > > > > > > news:5E1333EA-DD0D-4FCD-BD06-E34C1610CEB1@mi crosoft.com...
                    > > > > > > > Hello,
                    > > > > > > >
                    > > > > > > > I call a function recursively to find an item that exists[/color]
                    > > *anywhere*[color=darkred]
                    > > > > > down
                    > > > > > > > the chain. Let's say I find it five layers deep. Now I've got[/color][/color]
                    > what[color=green]
                    > > I[color=darkred]
                    > > > > > need
                    > > > > > > and
                    > > > > > > > want to break out of that whole stack and continue execution[/color][/color][/color]
                    at[color=blue][color=green]
                    > > the[color=darkred]
                    > > > > > point
                    > > > > > > of
                    > > > > > > > the initial call. Is that possible?
                    > > > > > > >
                    > > > > > > > Thanks,
                    > > > > > > >
                    > > > > > > > Bill
                    > > > > > >
                    > > > > > >
                    > > > > >
                    > > > > >
                    > > > >
                    > > > >
                    > > >
                    > > >[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    Working...