Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Below, is it possible to print No and have x be 2. That is, I'm looking for an And-like function that looks at all arguments before returning.

x := 1
If[And[True, False, True, False, (x := 2; True)], Print["Yes"], Print["No"]]; x
share|improve this question
up vote 12 down vote accepted

You can use And and still get what you want:

x := 1
If[And @@ {True, False, True, False, (x := 2; True)}, Print["Yes"], Print["No"]]; 

(* No
   2 *)

What happens is that the List and its arguments are evaluated before And is applied to it, hence setting the value of x.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.