Re: "short circuiting" And and Or
- To: mathgroup at smc.vnet.net
- Subject: [mg70610] Re: [mg70582] "short circuiting" And and Or
- From: Carl Woll <carlw at wolfram.com>
- Date: Sat, 21 Oct 2006 05:13:52 -0400 (EDT)
- References: <200610200921.FAA11062@smc.vnet.net>
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
>
>
In addition to using ReleaseHold/Hold, another idea is possible if
And[list] doesn't evaluate. For example:
condition[x_]:=(Print[x]; Positive[x])
condition /@ And @@ {1,1,-1,1,1,-1,1}
1
1
-1
False
Carl Woll
Wolfram Research
- References:
- "short circuiting" And and Or
- From: "Szabolcs Horvat" <szhorvat@gmail.com>
- "short circuiting" And and Or