mpsn Posted December 12, 2011 Share Posted December 12, 2011 Hi, recursion is something i love b/c it makes task easier but hard to master and use. Does anyone know any good books recommended for recursion, esp with for loops. Quote Link to comment Share on other sites More sharing options...
requinix Posted December 12, 2011 Share Posted December 12, 2011 Here is a fairly obvious link I can give you. Quote Link to comment Share on other sites More sharing options...
mpsn Posted December 12, 2011 Author Share Posted December 12, 2011 seriously, jokes aside, let's say i have this eg: void printnum ( $begin ) { echo $begin; if ($ begin < 9 ) { printnum ( $begin + 1 ); } echo $begin; } let's say $begin is 5, it will output: 5678998765 I don't understand how it knows to do the decrementing? Quote Link to comment Share on other sites More sharing options...
requinix Posted December 12, 2011 Share Posted December 12, 2011 There isn't any decrementing; $begin only goes up. There's three parts to the function: 1. Print $begin 2. Maybe call printnum with $begin+1 3. Print $begin Between steps 1 and 3 $begin does not change. It's still the same value as before because the two functions are running with different sets of variables. So if $begin is 5 the function will print 5 stuff 5 The "stuff" is whatever printnum($begin+1) prints. printnum(5) | printnum(6) | printnum(7) | printnum( | printnum(9) ------------+-------------+-------------+-------------+------------ print 5 | | | | --> | | | | print 6 | | | | --> | | | | print 7 | | | | --> | | | | print 8 | | | | --> | | | | print 9 | | | | print 9 | | | | | | print 8 | | | | | print 7 | | | | print 6 | | | print 5 | | | | Quote Link to comment Share on other sites More sharing options...
sandeep529 Posted December 30, 2011 Share Posted December 30, 2011 Here is a fairly obvious link I can give you. Nice one.. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 30, 2011 Share Posted December 30, 2011 To understand recursion, you must understand recursion. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted December 30, 2011 Share Posted December 30, 2011 Here is a fairly obvious link I can give you. lol, classic. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.