ending a recursive function

the_eagle_eyes
01-03-2005, 03:05 PM
Here is a copy of code I already have I am having trouble jumping out of the recursive loop when intLoop is -1. Any suggestions? :confused:


Function path(u As Integer, v As Integer, Q() As Integer) As Integer
Dim intLoop As Integer

intLoop = Q(u, v)

' Try if statements instead of case
Select Case (intLoop)
Case -1
'this is where I want to jump out of this function

Case 0
m = "A"

Case 1
m = "B"

Case 2
m = "C"

Case 3
m = "D"

Case 4
m = "E"

Case 5
m = "F"

Case 6
m = "G"

End Select

path = path(u, intLoop, Q)
txtPath.Text = m & "->"
End Function

Gruff
01-03-2005, 03:09 PM
Not sure what you are doing but 'Exit function' should kill the current leg of your recursive call.

OnErr0r
01-03-2005, 06:15 PM
You could shorten that quite a bit, try something like this:


Function path(u As Integer, v As Integer, Q() As Integer) As Integer
Dim intLoop As Integer

intLoop = Q(u, v)

If intLoop >= 0 Then
m = Chr$(intLoop + 65)

path = path(u, intLoop, Q)
End If
txtPath.Text = m & "->"
End Function

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum