MathGroup Archive 1996

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

Search the Archive

Re: Nonstandard use of Return[] ??

  • To: mathgroup at
  • Subject: [mg3618] Re: Nonstandard use of Return[] ??
  • From: wagner at bullwinkle.cs.Colorado.EDU (Dave Wagner)
  • Date: Thu, 28 Mar 1996 00:11:39 -0500
  • Organization: University of Colorado, Boulder
  • Sender: owner-wri-mathgroup at

In article <4j7h55$af4 at>,
Lou Pecora <pecora at> wrote:
>Try this:
>ff := ( Do[If[i<2,Return[1]],{i,3}]; Return[0])
>You'll get 0 and not 1.  Unlike the usual computer programming languages. 
>Strange choice of behavior.  However, I'm sure it's locked into
>Mathematica by now.
>Just a warning so others don't spend an hour debugging.
>Does anyone have a good way to exit the function totally?  I seem to
>remember some other kind of return once, but I can't find it.

You can use Throw and Catch to cause a non-local return:

(Local) In[9]:=
    gg := Catch[ Do[If[i<2,Throw[1]],{i,3}]; Throw[0] ]
(Local) In[10]:=
(Local) Out[10]=

		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at


  • Prev by Date: Is there a quaternion package for Mma?
  • Next by Date: Forcing sequential cell evaluation
  • Previous by thread: Nonstandard use of Return[] ??
  • Next by thread: Permanent Module (or Block) values: how?