# If statements with a Boolean [duplicate]

This question already has an answer here:

If I have a vector {1,2,3}, I want to write an If statement, where if one of the positions is "1", it will perform a certain command.

test = {1, 2, 3}
# == 1 & /@ test
If[# == 1 & /@ test == True, Print["Yes"], Print["no"]]


I get this as the output:

If[{True, False, False} == True, Print["Yes"], Print["no"]]


What am I doing wrong? I am new to Mathematica.

-

## marked as duplicate by Kuba, Yves Klett, m_goldberg, RunnyKine, Sjoerd C. de VriesApr 29 '14 at 21:43

This question was marked as an exact duplicate of an existing question.

Use MemberQ to test if an element is in the list. – Szabolcs Apr 29 '14 at 18:31
You should study the answers to this question Map a function across a list conditionally. In fact this is a duplicate. – Artes Apr 29 '14 at 18:34

## 1 Answer

There are a number of different solutions. Here are a few:

test = {1, 2, 3}
# == 1 & /@ test

If[Or @@ Thread[# == 1 & /@ test == True], Print["Yes"], Print["no"]]
If[Or @@ (# == 1 & /@ test), Print["Yes"], Print["no"]]
If[MemberQ[test, 1], Print["Yes"], Print["No"]]


In my opinion these are in increasing order of clarity and good practice.

-