MathGroup Archive 2006

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

Search the Archive

Re: "short circuiting" And and Or

  • To: mathgroup at
  • Subject: [mg70608] Re: [mg70582] "short circuiting" And and Or
  • From: János <janos.lobb at>
  • Date: Sat, 21 Oct 2006 05:13:48 -0400 (EDT)
  • References: <>

On Oct 20, 2006, at 5:21 AM, Szabolcs Horvat wrote:

> I'd like to write a function that tests whether there are any elements
> in a list that violate a certain condition. I could simply use
> And@@condition/@list, but for reasons of efficiency I'd like to stop
> the testing as soon as a "False" value is found. Is there any elegant
> way of doing this without writing an explicit While loop?
> Szabolcs Horvát

Here is a newbie approach:

lst = {1, 2, 3, 4, 5, 6, 7,
     8, 9.1, 10, 11, 12};

f[x_] := If[x \[Element] Integers,
    Null, Throw[x]];

Catch[Scan[f, lst]]


Trying to argue with a politician is like lifting up the head of a  
(S. Lem: His Master Voice)

  • Prev by Date: Plot3D question
  • Next by Date: Re: Programming style: postfix/prefix vs. functional
  • Previous by thread: Re: "short circuiting" And and Or
  • Next by thread: Re: "short circuiting" And and Or