Re: Help with functions
- To: mathgroup at smc.vnet.net
- Subject: [mg65647] Re: Help with functions
- From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
- Date: Wed, 12 Apr 2006 05:59:56 -0400 (EDT)
- Organization: Uni Leipzig
- References: <e1fop2$bb4$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
the manual say
Unless an explicit Return is used, the value
returned by Do is Null.
because Return[] does an escape from the Do[]
loop, but not from
the function, it enclose it. And you need
fun[x_] := Module[{i, val},
val = Do[If[i == 2, Return[False]], {i, 5}];
Return[If[Null =!= val, val, True]];
]
Regards
Jens
"IronBone" <iron.bone at op.pl> schrieb im
Newsbeitrag news:e1fop2$bb4$1 at smc.vnet.net...
|I have written a simmple function which (in my
opinion) should always
| return False. But it returns True.
|
| It seems that Return[False] breaks the Do loop
but not returns from the
| function.
| I thing I don't understand, what is defining of
functions. Can somebody
| explain me this.
|
| fun[x_] := Module[{i},
| Do[If[i == 2, Return[False]], {i, 5}];
| Return[True];
| ]
|
|
| I.B.
|