Return in function
- To: mathgroup at smc.vnet.net
- Subject: [mg105621] Return in function
- From: dh <dh at metrohm.com>
- Date: Fri, 11 Dec 2009 06:46:49 -0500 (EST)
Version 7.0.1 Hello, I am not sure if this is a feature or a bug. If you use Return in an anonymous function, not only the return value is returned, but also "Return" itself. Consider: (If[# == 2, Return[a]; #, #]) & /@ {1, 2, 3} this gives: {1, Return[a], 3} The same thing happens with: Function[x, If[x == 2, Return[a]; x, x]] /@ {1, 2, 3} However, the following works as expected: f[x_] := (If[x == 2, Return[a]; x, x]); f /@ {1, 2, 3} Daniel
- Follow-Ups:
- Re: Return in function
- From: Leonid Shifrin <lshifr@gmail.com>
- Re: Return in function
- From: DrMajorBob <btreat1@austin.rr.com>
- Re: Return in function