Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: Early out with Map?

  • To: mathgroup at
  • Subject: [mg16127] Re: [mg16036] Early out with Map?
  • From: Andrzej Kozlowski <andrzej at>
  • Date: Sat, 27 Feb 1999 03:23:01 -0500
  • Sender: owner-wri-mathgroup at

On Sat, Feb 20, 1999, Oscar Stiffelman <ostiffel at> wrote:

>Is it possible to interrupt Map before it reaches then end of the list?
>For example, how would I convert the following from procedural to
>(* This is the procedural version *)
>foundSolution = False;
>For[i =1, i <= numChildren && ! foundSolution, i++,
>    If[testChild[children[[i]]],
>        foundSolution = True;
>      ];
>* This keeps going until it reaches the end of the list.
>* I would prefer to return as soon as testChild returns True
>Or @@ Map[testChild, children]
>* This does not actually return
>Map[If[testChild[#], Return[True], False]&, children]
Scan will do exactly what you want, If I have understood you correctly.
The way to use it is 


You will get True the first time Scan finds an element of children for
which testChild is True.

Andrzej Kozlowski
Toyama International University

Andrzej Kozlowski
Toyama International University

  • Prev by Date: Re: Evaluate/Module[Correction]
  • Next by Date: problem with integral
  • Previous by thread: Re: Early out with Map?
  • Next by thread: Graphics over mathlink.