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

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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