# Thread: Any examples handy for explaining what "Iterative" and "Recursive

1. ## Any examples handy for explaining what \"Iterative\" and \"Recursive

User Buzzi, Allan (abuzzi@waterways.nsw.gov.au.nospam) posted:

I'm after examples of Iterative and Recursive functions (explaining the
differences between the two (ie - what types of situations you would use one
in, as opposed to the other)).

I look forward to seeing what info you guys could forward to me, on this
area.

Al
CONFIDENTIALITY NOTICE: This message transmission (including any
accompanying documents) may contain information which is confidential and or
privileged. As a result if you are not the intended recipient, any
dissemination, copying or action taken in reliance on the contents of the
message is strictly prohibited. If you have received this message in error
you are requested to notify the sender and delete the message.

Views expressed in this message are those of the sender rather than the
Waterways Authority unless the content of the message indicates to the
contrary.

---

2. ## Re: Any examples handy for explaining what \"Iterative\" and \"Recursive

User DAVID MARSH (DAVID.MARSH@thales-cs.com.nospam) posted:

I would use a recursive function as a last resort, coz they are difficult to
write and mantain. Typical uses, loan calculations, annoying computer
science students with the towers of Hannoi problem.

Probably the simplist one is factorials

4! = 4 * 3!
3! = 3 * 2!
2! = 2 * 1!
1! = 1 * 0!
0! = 1

Function FactorialFinder(iFactorialToFind as Integer) as Integer

Dim iFactorialResult as Integer

If iFactorialToFind > 0 Then
iFactorialResult = iFactorialToFind *
FactorialFinder(iFactorialToFind - 1)
Else
iFactorialResult = 1
End If

FactorialFinder = iFactorialResult

End Function

Which is hard to dry run and doesn't do much more than (than make the coder
feel superior)

Function FactorialFinder(iFactorialToFind as Integer) as Integer

Dim iFactorialResult as Integer
Dim iLoopCount As interger

iFactorialResult = 1
For iLoopCount = 1 to iFactorialToFind
iFactorialResult = iFactorialResult * iLoopCount
next iLoopCount

End Function

There are also issues of pushing and pulling stuff on and off staks that can
have issues in extreme cases

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.