MathGroup Archive 2012

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

Search the Archive

Re: Exiting a Nested operation...


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.



  • Prev by Date: Re: Transforming/expanding a list
  • Next by Date: Re: DSolve for a real function
  • Previous by thread: system of simple PDE
  • Next by thread: Using code from nb. file in NetLink