Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

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

  • To: mathgroup at
  • Subject: [mg21937] Re: How to Break[] out of nested loops?
  • From: pecora at (Lou Pecora)
  • Date: Sat, 5 Feb 2000 00:49:14 -0500 (EST)
  • Organization: Naval Research Lab
  • References: <86r7bm$> <870vkl$> <87duti$2jv$>
  • Sender: owner-wri-mathgroup at

In article <87duti$2jv$5 at>, Ed McBride
<emcbride at> 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
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:
  * The 5th Experimental Chaos Conference Orlando FL June 1999.
Check it out at
  * The 4th Experimental Chaos Conference Sessions & Abstracts Online:, 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