can function call it self then how explain

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ram9820
    New Member
    • Jan 2012
    • 1

    can function call it self then how explain

    can function call it self then how explain
  • C CSR
    New Member
    • Jan 2012
    • 144

    #2
    Yes. Its called "Recursion, " and if you don't have a way to end it you will crash--loops until your out of memory. I'd give you an example but you didn't say what language you're using.

    Comment

    • C CSR
      New Member
      • Jan 2012
      • 144

      #3
      Here's a basic example I snatched from a helpfile in MSAccess. Just adapt the concept to your code. Watch the output; it climbs up through the repeated function calls, then backs back down when it hits a certain condition. Step through it to fully understand the action & results of your variables.

      Code:
      Function Factorial(N)
          If N <= 1 Then    ' Reached end of recursive calls.
              Factorial = 1    ' (N = 0) so climb back out of calls.
          Else    ' Call Factorial again if N > 0.
              Debug.Print "FuncN =" & N
              Factorial = Factorial(N - 1) * N
          End If
      End Function

      Comment

      Working...