| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Rexx |
* Reply to message in Sysop's Personal Mail
Hello Francois!
Replying to a message of Francois Thunus to Steven Cox:
FT> Hello Steven!
FT> 24 Sep 95 22:36, Steven Cox wrote to All:
SC>> I am trying to learn Rexx. I am studying Rexx in 21 days by William
SC>> & Esther Schindler. I got to this example of recursion & cannot
SC>> figure it out. This program figures the factorial of a number. Would
SC>> someone please explain how this works.
FT> what is it exactly that you want to know or don't understand ? the
FT> rexx syntax or the recursion phenomenon? recursion is easy to explain
FT> and hard to understand: it's using the hammer you are making to built
FT> a hammer. as for the rexx syntax, I can hardly comment on 20 lines of
FT> code...
I understand what recursion does and somewhat how it does it. It is this
particular procedure I do not understand. (I think...)
[C:\rexx_in_21]list1406
5 *-* Say 'Enter a number:';
>>> "Enter a number:"
Enter a number:
6 *-* Pull number;
5
>>> "5"
7 *-* Say number || '! is' Factorial(number);
10 *-* Factorial:
10 *-* Procedure;
11 *-* num = Arg(1);
>>> "5"
12 *-* If num = 1;
>>> "0"
14 *-* Return Factorial(num - 1) * num; /* if num = 5 then
5-1=4*5=20 This is were i loose it!!*/ /* I'm not sure I understand
this return instruction....It is returning to itself as I see it*/
10 *-* Factorial:
10 *-* Procedure;
11 *-* num = Arg(1);
>>> "4"
12 *-* If num = 1;
>>> "0"
14 *-* Return Factorial(num - 1) * num;
10 *-* Factorial:
10 *-* Procedure;
11 *-* num = Arg(1);
>>> "1"
12 *-* If num = 1;
>>> "1"
12 *-* Then;
13 *-* Return num;
>>> "1"
>>> "2" /* Now where did this
come from?? */
>>> "6"
>>> "24"
>>> "120"
>>> "5! is 120"
5! is 120
8 *-* Exit;
/* this it the program.*/
/* list1406.cmd */
/* Calculating factorial using a recursive function. */
TRACE RESULT
SAY 'Enter a number:'
PULL number
SAY number || '! is' Factorial( number)
EXIT
Factorial: PROCEDURE
num = Arg( 1 )
IF num = 1 THEN
RETURN num
RETURN Factorial( num - 1 ) * num
Thanks for your help,
Steven
PS. Sorry I haven't responded sooner, I have been real busy & this had
to be put on the side. So much for 21 days.
--- FleetStreet 1.03 NR==LoraBBS OS/2 v2.40+
* Origin: Information Exchange, Houma, LA. (504)872-4275 (1:384/14)SEEN-BY: 270/101 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407 SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809 @PATH: 384/14 1 3615/50 396/1 270/101 712/515 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.