Which
✖
Which
Details

- Which has attribute HoldAll.
- If any of the testi evaluated by Which give neither True nor False, then a Which object containing these remaining elements is returned unevaluated. »
- You can make Which return a "default value" by taking the last testi to be True.
- If all the testi evaluate to False, Which returns Null.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
In[1]:=1

✖
https://wolfram.com/xid/0binpz92-bqbdxr
Out[1]=1

Scope (4)Survey of the scope of standard use cases
Programming Behavior (3)
Which can be maintained in symbolic form:
In[1]:=1

✖
https://wolfram.com/xid/0binpz92-dhl9dl
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/0binpz92-l7lis
Out[2]=2

Conditions are evaluated until one is found that is neither True nor False:
In[1]:=1

✖
https://wolfram.com/xid/0binpz92-ijkmky
Out[1]=1

Use True for an else clause that always matches:
In[1]:=1

✖
https://wolfram.com/xid/0binpz92-0ywjq5
In[2]:=2

✖
https://wolfram.com/xid/0binpz92-dwhp6j
Out[2]=2

Symbolic Transformations (1)
In[1]:=1

✖
https://wolfram.com/xid/0binpz92-k3irbe
Out[1]=1

Expand it to use Piecewise:
In[2]:=2

✖
https://wolfram.com/xid/0binpz92-7fdp3
Out[2]=2

In[3]:=3

✖
https://wolfram.com/xid/0binpz92-gy70lb
Out[3]=3

In[4]:=4

✖
https://wolfram.com/xid/0binpz92-brjttk
Out[4]=4

In[5]:=5

✖
https://wolfram.com/xid/0binpz92-f86ls1
Out[5]=5

In[6]:=6

✖
https://wolfram.com/xid/0binpz92-c41afg
Out[6]=6

Properties & Relations (2)Properties of the function, and connections to other functions
Use Which rather than a nested if-then-elseif chain:
In[1]:=1

✖
https://wolfram.com/xid/0binpz92-iwoavx
In[2]:=2

✖
https://wolfram.com/xid/0binpz92-bqb1ti
Out[2]=2

In[3]:=3

✖
https://wolfram.com/xid/0binpz92-i0gxyp
In[4]:=4

✖
https://wolfram.com/xid/0binpz92-gmohah
Out[4]=4

Use PiecewiseExpand to convert Which to Piecewise:
In[1]:=1

✖
https://wolfram.com/xid/0binpz92-gl01e8
Out[1]=1

In[2]:=2

✖
https://wolfram.com/xid/0binpz92-wfdrf
Out[2]=2

In[3]:=3

✖
https://wolfram.com/xid/0binpz92-cai747
Out[3]=3

Wolfram Research (1988), Which, Wolfram Language function, https://reference.wolfram.com/language/ref/Which.html.
✖
Wolfram Research (1988), Which, Wolfram Language function, https://reference.wolfram.com/language/ref/Which.html.
Text
Wolfram Research (1988), Which, Wolfram Language function, https://reference.wolfram.com/language/ref/Which.html.
✖
Wolfram Research (1988), Which, Wolfram Language function, https://reference.wolfram.com/language/ref/Which.html.
CMS
Wolfram Language. 1988. "Which." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Which.html.
✖
Wolfram Language. 1988. "Which." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Which.html.
APA
Wolfram Language. (1988). Which. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Which.html
✖
Wolfram Language. (1988). Which. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Which.html
BibTeX
✖
@misc{reference.wolfram_2025_which, author="Wolfram Research", title="{Which}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/Which.html}", note=[Accessed: 05-June-2025
]}
BibLaTeX
✖
@online{reference.wolfram_2025_which, organization={Wolfram Research}, title={Which}, year={1988}, url={https://reference.wolfram.com/language/ref/Which.html}, note=[Accessed: 05-June-2025
]}