Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11648 > unrolled thread

Re: Exiting a Nested operation...

Started byDaniel <dosadchy@its.jnj.com>
First post2012-09-07 08:58 +0000
Last post2012-09-07 08:58 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Exiting a Nested operation... Daniel <dosadchy@its.jnj.com> - 2012-09-07 08:58 +0000

#11648 — Re: Exiting a Nested operation...

FromDaniel <dosadchy@its.jnj.com>
Date2012-09-07 08:58 +0000
SubjectRe: Exiting a Nested operation...
Message-ID<k2ccuo$f37$1@smc.vnet.net>
To exit Nest when some condition is met you can Throw an exception, like this:

result=NestWhile[
(your code ...
..
If[finalConditionIsMet, Throw[someResult]];
..
.. you code end),
initial,
True&]//Catch;

This NextWhile is supposed to run indefinitely (because of the 'True&' as test function), but will exit when 'finalConditionIsMet' is True.

For debug you should probably use something like this:

result=Nest[
(your code ...
..
If[finalConditionIsMet, Throw[someResult]];
..
.. you code end),
initial,
50]//Catch;

so the NestWhile will not run indefinitely if you have a bug.

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web