Need Help in Recurssion

Hi there

I got  a follows

Function1(x as integer)

if (x>=2) then
return function1(x-1) + function1(x-2)
return 0
end if

i want to know how many times the function1 will call
and if possible give me some more detailed explanation about calling the function

thanks & regards
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Harisha M GEngineerCommented:

It depends on the value of x...

When x = 2, it will get called twice
When x = 3, it will get called 2 + 1 = thrice
When x = 4, 3 + 2 = 5 times
When x = 5, 5 + 3 = 8 times


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Yes it depends on the value of x but I think the values mgh_mgharish provided

It looks like you're using (using return)

By the way its a good idea to add a counter to the function to see exactly how many times it is called:

Dim counter As Integer

Private Function Function1(x As Integer)
    If (x >= 2) Then
        Function1 = Function1((x - 1) + Function1(x - 2))
        Function1 = 0
    End If
    counter = counter + 1
End Function

Private Sub Command1_Click()
    Counter = 0
    Function1 9
    MsgBox Counter
End Sub
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.