Null Return for a Module
- To: mathgroup at smc.vnet.net
- Subject: [mg88666] Null Return for a Module
- From: Dave the Funkatron <dave.rudolf at usask.ca>
- Date: Mon, 12 May 2008 04:45:17 -0400 (EDT)
Hi all,
I'm getting strange output and am trying to track down what might be
causing it. I have the following code in my .nb file:
(* begin code *)
Test[ ] := Module[ {i, thesum},
thesum = 0;
For[ i = 1, i <= 3, i++,
thesum = thesum + i
]
Return[ thesum ]
]
Test[ ]
(* end code *)
The output I would expect would be simply
6
But, I get
Null Return[6]
Alternatively, if I change the last line of the Test function to be
thesum
instead of
Return[ thesum ]
I get
6 Null
as the output. If I remove the for loop, I get expected behavior,
i.e.,
Test[ ] := Module[ {i, thesum},
thesum = 1 + 2 + 3;
(*
For[ i = 1, i <= 3, i++,
thesum = thesum + i
]
*)
Return[ thesum ]
]
yields the output
6
as one might expect. I'm not sure what this all means, or what it is
complaining about. I have other for-loops that are apparently working
properly. So, can anyone give me an idea what might be going wrong
here?
Thanks.
Dave
- Follow-Ups:
- Re: Null Return for a Module
- From: "W_Craig Carter" <ccarter@mit.edu>
- Re: Null Return for a Module