MathGroup Archive 1996

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

Search the Archive

Nonstandard use of Return[] ??

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3583] Nonstandard use of Return[] ??
  • From: pecora at zoltar.nrl.navy.mil (Lou Pecora)
  • Date: Wed, 27 Mar 1996 03:25:54 -0500
  • Organization: Naval Research Lab
  • Sender: owner-wri-mathgroup at wolfram.com

Despite using Mathematica off and on for years, I still get bitten by
something.  This time it was the nonstandard use of Return[].  I thought
Return[] would exit a function (completely!), but it doesn't.  It just
exits a loop and remains within a function.

Try this:

In:=
ff := ( Do[If[i<2,Return[1]],{i,3}]; Return[0])

In:=
ff

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.

-- 
Lou Pecora
code 6341
Naval Research Lab
Washington  DC  20375
USA
pecora at zoltar.nrl.navy.mil
/* My views are not those of the U.S. Navy. 
   If you want their views, you have to go to war. */

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Re: Encrypting .m, .ma files
  • Next by Date: Re: mathematica-macppp conflict
  • Previous by thread: Showing infinite values in Grafics ??
  • Next by thread: Re: Nonstandard use of Return[] ??