Return
- To: mathgroup at smc.vnet.net
- Subject: [mg32308] Return
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Sat, 12 Jan 2002 05:18:25 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
In view of the recent thread on Holding Arguments in a Second Argument List
the following notes on Return may be of interest:
If Return[x] is generated as a value in Do or Scan then x is immediately
returned;
If Return[x] is generated as an entry in CompoundExpression or as a value
of the body of a While or For loop then Return[x] (not x) is immediately
returned;
If Return[x] is generated as the value of a user-defined function then the
function returns x (not Return[x])
Otherwise Return[x] behaves as a ordinary expression.
EXAMPLES
Do[Return[2],{4}]
Scan[If[#>1,Return[#]]&, {1,2,3}]
2
2
1;Return[2];3
While[True, Return[2]]
For[1,True,2, Return[2]]
Return[2]
Return[2]
Return[2]
f[x_]:= Return[x]
f[2]
2
{Return[2]}
{Return[R[2]]}
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565