From: Panagiotis Atmatzidis Date: 2010-01-04T01:16:21+09:00 Subject: Few clarifications on recursion --Apple-Mail-1-760334993 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hello, I'm following C. Pine's manual for a smooth intro into ruby & = programming. I'm just curious about this exercise which should teach = recursion. Here is the program sample, which as you can see is a simple factorial = calculator: def factorial num if num < 0 return 'You can\'t take the factoria of a negative number' end if num <=3D 1 1 else num * factorial(num-1) end end Although it introduces many interesting concepts to me (i. e. I did not = knew that after the "if" statement a single _1_ with no quotes could be = used) I fail to see how the num changes value. The way I read the code = here: num * factorial(num-1) is 30*29 for "puts factorial(30)" not 30*29*28... which is how it works. = I've tested the code works fine. The book although, in my opinion is excellent (so far) for starters, = does not explain - or it does but I did not understand it nevertheless - = how this piece of code works. regards Panagiotis (atmosx) Atmatzidis email: atma@convalesco.org URL: http://www.convalesco.org GnuPG ID: 0xFC4E8BB4=20 gpg --keyserver x-hkp://pgp.mit.edu --recv-keys 0xFC4E8BB4 -- The wise man said: "Never argue with an idiot. They bring you down to = their level and beat you with experience." --Apple-Mail-1-760334993--