Re: Exiting a Nested operation...

*To*: mathgroup at smc.vnet.net*Subject*: [mg127991] Re: Exiting a Nested operation...*From*: Daniel <dosadchy at its.jnj.com>*Date*: Fri, 7 Sep 2012 04:58:50 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*Delivered-to*: l-mathgroup@wolfram.com*Delivered-to*: mathgroup-newout@smc.vnet.net*Delivered-to*: mathgroup-newsend@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.