Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursion?
#1
Hmm, I've seen a lot about something called recursion lately.
Problem is, I don't know what it is...Something to do with loops?
Can anyone tell me?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#2
sub recursivesub (x as integer)
x = x + 1
print x
recursivesub(x)
end sub

this is recursive. calling a routine within itself to make a more complicated routine. but since qb's stack handling sucks, it's not a very fast or crash-proof method in qb.

but might i suggest checking out the power of: GOOGLE!
http://www.google.com/search?hl=en&ie=UT...=recursion
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply
#3
Quote:calling a routine within itself to make a more complicated routine

I always thought it was easier to write a recursive routine(sometimes) than a non recursive rotuine, and thats why its used, not to make it more complicated....
b]Hard Rock[/b]
[The Stars Dev Company] [Metal Qb flopped] [The Terror]
Stop Double Posts!
Whats better? HTML or Variables?
Reply
#4
the code becomes less complicated if you rank it -by size- but the actual workings of the code becomes more complicated.

Besides, recursion (at least in QB) uses dynamic arrays within arrays 9the QB stack size). Dynamic arrays are slow. Also, recursion is usually less efficient than iteration because you have to store the current line position of each instance and that eats a lot of stack space, too.

Of course it makes things easier on the outside but I like iterative more. (which is harder to program, usually)
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#5
Wouldn't that SUB of toonski84's create an infinate loop?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#6
Quote:Wouldn't that SUB of toonski84's create an infinate loop?

Yeah. That's why the base case is introduced.

Think for example about the caluculus of a factorial number. For example, 4! is 4*3*2*1. You can now express it in this manner:

Code:
x! = (x-1)! * x    if x>1,
x! = 1 if x = 1

The second line is the base case. As you see, the first line uses a recursive call, as x! is defined using a previous value (x-1)!. The second line doesn't make any recursive call, so when x reaches 1 there won't be more calls. This, in QB...

Code:
FUNCTION factorial! (n!)
   IF n!>1 THEN
      result! = factorial!(n!-1)*n!
   ELSE
      result!=1
   ENDIF
   factorial! = result!
END FUNCTION
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#7
My god!!! Calculus!!!
*screams and faints*
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#8
calculus? Wha--where? :roll:
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#9
Quote:My god!!! Calculus!!!
*screams and faints*

It ain't calculus. 1st year HS math would teach you factorial since they are needed for things like:

Combinations.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#10
i learned factorials in 6th grade prealgebra. if you were using the formula to estimate factorials and performing integrals and whatnot then yeah, it'd be calculus but he dont use it.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)