Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to do Factorials in VFP with Recursion
Message
From
22/02/2000 01:01:46
 
 
To
22/02/2000 00:06:50
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00335196
Message ID:
00335255
Views:
18
>What 'types' of programs do you recommend using recursion? I've used them for multi-level types of organizations and relationships where they seem to do well. I'm curious as to other types of applications as well.

Here's the rule of thumb given by one of my professors:

You assume that:
1. You have a little devil-slave that knows how to calculate MyProblem(x)
and
2. You know how to go from y to x
and
3. You know when to stop

Then it's easy to apply a recursive solution:

func MyProblem
lparam y
if MyStopCondition(y)
return whatever && This is my precious knowledge
else
x = NextStepParam(y) && Again, my knowledge
a = MyProblem(x) && Again, my knowledge
return Operate(a, y) && Again, my knowledge
endif

And, as it can be seen, there's no little devil involved at all... :) The devil-slave is just the above pattern. In practice,
there are three important things: the above pattern, the stop condition (very important to be sure that it will
be meet for all cases) and the formula to go from one step to the other (params and result).

Obviously, NextStepParam and Operate can be simple formulas.

Vlad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform