Re: How to Break[] out of nested loops?
- To: mathgroup at smc.vnet.net
- Subject: [mg21937] Re: How to Break[] out of nested loops?
- From: pecora at zoltar.nrl.navy.mil (Lou Pecora)
- Date: Sat, 5 Feb 2000 00:49:14 -0500 (EST)
- Organization: Naval Research Lab
- References: <86r7bm$b72@smc.vnet.net> <870vkl$8ni@smc.vnet.net> <87duti$2jv$5@dragonfly.wolfram.com>
- Sender: owner-wri-mathgroup at wolfram.com
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.
--------------------------------------------------------------------