MathGroup Archive 2000

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

Search the Archive

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


Use the Catch Throw commands :

Catch[
myMultiLeveledLoopContainingAThowClause[]
]

On Fri, 28 Jan 2000, Julin Aguirre wrote:
> In a loop like
> 
> Do[
> x=LengthyComputation[m];
>     Do[
>        If[condition[x,n], Break[]],
>     {n, nmax}],
> {m, mmax}]
> 
> the Break[] exits the inner loop. Is there a way of exiting out of the outer
> loop? I do not want to write like
> 
> Do[
> x=LengthyComputation[m];
> If[condition[x,n], Break[]],
> {m, mmax},{n, nmax}]
> 
> because then LengthyComputation[m] is calculated nmax times for each value
> of m isnstead of just once.
> 
> Thanks in advance.
> 
> -- 
> Julian Aguirre
> Universidad del Pais Vasco


  • Prev by Date: Re: ToString[Hold[a]] gives Hold[a]
  • Next by Date: Re: Improvements
  • Previous by thread: How to Break[] out of nested loops?
  • Next by thread: Re: How to Break[] out of nested loops?