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"

< Previous CommentHelp | Reply To Comment | Reply To Topic
Author Comment/Response
Bill Simpson
12/19/12 10:36pm

In Response To 'Re: While-Loop inside Module doesn't work'
---------
The result returned from Module[] is going to be the last expression inside the Module.

In your example the last expression is While[] and that returns Null.

If you want to have the result from your faculty function to be u then you should have

faculty[x_]:=Module[
...
While[
...
];
u
];
faculty[3]

You can try it with and without that added u and verify this for yourself.

It is generally a bad idea to not separate every pair of expressions with a semicolon. Sometimes you can get away without this, but not including semicolons has been a source of puzzling errors for many years.

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
< Previous CommentHelp | Reply To Comment | Reply To Topic