MathGroup Archive 2004

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

Search the Archive

Re: First question


dto_mba at skynet.be wrote:
> 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
> 
Read in the docs about Catch[] and Throw[]:

lmaa := Module[{},
    Do[If[i > 3, Throw[{"from inside"}]],
      {i, 1, 5}];
     {"not from inside"}]

Catch[lmaa]
{"from inside"}

-- 
Peter Pein
Berlin


  • Prev by Date: Re: fourier ( FFT )
  • Next by Date: Re: fourier ( FFT )
  • Previous by thread: Re: First question
  • Next by thread: Re: First question