MathGroup Archive 2006

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

Search the Archive

Re: "short circuiting" And and Or

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

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:

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

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

In[3]:=
Catch[Scan[f, lst]]
Out[3]=
9.1

János


----------------------------------------------
Trying to argue with a politician is like lifting up the head of a  
corpse.
(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