| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Rexx |
Hello All!
I am trying to learn Rexx. I am studying Rexx in 21 days by William &
Esther Schindler. I got to this example of recursion & cannot figure
it out.
This program figures the factorial of a number. Would someone please
explain how this works.
[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; /* I thought this
should be (5-1) X 5 or 20 */
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);
>>> "3"
12 *-* If num = 1;
>>> "0"
14 *-* Return Factorial(num - 1) * num;
10 *-* Factorial:
10 *-* Procedure;
11 *-* num = Arg(1);
>>> "2"
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"
/* where did this come from */
>>> "2"
/* " " " " "
*/
>>> "6"
/* " " " " "
*/
>>> "24"
/* " " " " "
*/
>>> "120"
/* " " " " " */
>>> "5! is 120"
5! is 120
8 *-* Exit;
Thanks for the help,
Steven
--- FleetStreet 1.03 NR==LoraBBS OS/2 v2.40+
* Origin: Information Exchange, Houma, LA. (504)872-4275 (1:384/14)SEEN-BY: 105/42 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 105/103 42 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™.