VBA/Excel/Access/Word/Language Basics/Recursive — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:33, 26 мая 2010

A recursive procedure is one that calls itself.

 
Public Function Factorial(N As Integer) As Integer
    If N <= 1 Then
        Factorial = 1
    Else
        Factorial = Factorial(N - 1) * N
    End If
End Function
Sub res()
   Debug.Print Factorial(4)
End Sub



Recursive function to calculate the faculty of x

 
Public Sub testrecur()
  Debug.Print recur(3)
End Sub
Function recur(x)
  If x <= 1 Then
    recur = 1
  Else
    recur = x * recur(x - 1)
  End If
End Function



Recursive Procedures

 
Function GetFactorial(intValue As Integer) As Double
    If intValue <= 1 Then
        GetFactorial = 1
    Else
        GetFactorial = GetFactorial(intValue - 1) * intValue
    End If
End Function
Sub RecursiveFunction()
   Debug.Print GetFactorial(3)
End Sub