MathGroup Archive 2000

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

Search the Archive

Re: How to Break[] out of nested loops?


In article <87duti$2jv$5 at dragonfly.wolfram.com>, Ed McBride
<emcbride at wybron.com> wrote:

> > Julian:
> > 
> > Suggestion: use Throw and Catch:
> > 
> > x = 0;
> > Do[x = m^2;
> >     Do[If[2n + x > 30, Throw[Null]], {n, 5}], {m, 7}] // Catch
> > 
> > Allan
> > ---------------------
> 
> Or, if you happen to be an organized, disciplined person who does not
> rank go-to-type statements right up there with sacrilege, you could even
> stoop to a "Goto" statement.  I mean, if God didn't want us to use this
> statement, why would Mr. Wolfram have been 
> permitted to include it in his software package?
> Ed McBride, P.E.

I have to agree with this.  Sometimes efforts to break from nested loops
can become complicated, even arcane (e.g. above, using exceptions to break
form loops? -- no offense intended).  When you want to just get out of
something a clear Goto a label works fine.  Same in C.

Lou Pecora,  email:  pecora at anvil.nrl.navy.mil
Naval Research Laboratory, Washington, D.C. 20375-5000, U.S.A.
 == My comments are my own and do not reflect the views of the U.S. Navy. ==
 == No Spamming or solicitations -- both are illegal at this site ==
--------------------------------------------------------------------
Check out our Nonlinear Dynamics Web site: http://chaos-mac.nrl.navy.mil/
--------------------------------------------------------------------
  * The 5th Experimental Chaos Conference Orlando FL June 1999.
Check it out at  http://www.physics.gatech.edu/ecc5/
  * The 4th Experimental Chaos Conference Sessions & Abstracts Online: http://natasha.umsl.edu/Exp_Chaos4, proceedings available.
--------------------------------------------------------------------


  • Prev by Date: Re: Word processing in Mathematica?
  • Next by Date: Re: NDSolve series of ode with equilibrium conditions
  • Previous by thread: Re: How to Break[] out of nested loops?
  • Next by thread: Re: NDSolve and numeric-only computation