Return

16 views
Skip to first unread message

Allan Hayes

unread,
Jan 12, 2002, 5:27:53 AM1/12/02
to
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
h...@haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

Reply all
Reply to author
Forward
0 new messages