Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'While-Loop inside Module doesn't work' topicStudent Support Forum > General > "While-Loop inside Module doesn't work"

Next Comment >Help | Reply To Topic
Author Comment/Response
xavier
12/18/12 12:33pm

I am a mathematica newbee. I wanted to write a procedure which evaluates the faculty of a natural number (I only want that procedure so that I get used to the mathematica modules; so I know how to code a simpler program which solves this).

This is my code:

faculty[x_] := Module [{u},
product = 1;
u = 1;
While[u <= x,
product = product*u;
u = u + 1
](*While*)
](*Module*)
faculty[3]

If I run that program I don't get any output. I wanted Mathematica to print 6 (which is the same as 3!).
Until now I have never seen a Module with a While-Loop inside. Is there any reason why While can't be used inside a Module?

I am very thankful for every help!

xavier

URL: ,

Subject (listing for 'While-Loop inside Module doesn't work')
Author Date Posted
While-Loop inside Module doesn't work xavier 12/18/12 12:33pm
Re: While-Loop inside Module doesn't work xavier 12/19/12 09:16am
Re: Re: While-Loop inside Module doesn't work jf 12/19/12 10:37am
Re: Re: While-Loop inside Module doesn't work Bill Simpson 12/19/12 10:36pm
Next Comment >Help | Reply To Topic