MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: First question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52111] Re: First question
  • From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
  • Date: Thu, 11 Nov 2004 04:52:14 -0500 (EST)
  • Organization: Uni Leipzig
  • References: <cmsp1e$bah$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."

and that mean tha Return[] in a Do[]-Loop terminate the Do[] loop

and not the function. You mean



lmaa [] := Module[{i},
             res = Do[
                     If[i > 3, Return[{"from inside"}]],
                     {i, 0, 5}
                    ];
             If[Null === res, {"not from inside"}, res]
            ]



or

lmaa [] := Module[{i = 0},
             While[i < 6,
               If[i > 3, Return[{"from inside];
               i++
              ];
             {"not from inside"}
            ]

lmaa [] := Module[{i},
             For[i = 0, i < 6, i++,
               If[i > 3, Return[{"from inside"}]]
              ];
             {"not from inside"}
            ]

Regards

  Jens

<dto_mba at skynet.be> schrieb im Newsbeitrag news:cmsp1e$bah$1 at smc.vnet.net...
> How to exit directly and immediately a module from inside a loop with
> a certain value ?
> Return seems not to work.
>
> Example:
>
> lmaa := Module[
> {},
>   Do[
>     If[i > 3, Return[{"from inside"}]],
>     {i, 1, 5}
>   ];
>   Return[{"not from inside"}]
> ]
>
>
> lmaa
>
> {not from inside}
>
> Best
>
> Gilbert Gosseyn
> 



  • Prev by Date: Re: Two y-axes in one graph
  • Next by Date: equal distribution of last digits base ten in the primes by b-normality
  • Previous by thread: Re: First question
  • Next by thread: Re: First question