Wolfram Function Repository (Under Development)
Instant-use add-on functions for the Wolfram Language
An operator form of Which
ResourceFunction["When"][test1,value1,test2,value2,…][e] evaluates each of the testi[e] in turn, returning the value of the valuei corresponding to the first test that yields , otherwise yields e unchanged. |
When evaluates the corresponding value only when the specified condition is met:
In[1]:= |
![]() |
In[2]:= |
![]() |
Out[2]= |
![]() |
Use a single test with When:
In[3]:= | ![]() |
Out[3]= | ![]() |
In[4]:= | ![]() |
Out[4]= | ![]() |
Try several tests in turn:
In[5]:= | ![]() |
Out[5]= | ![]() |
In[6]:= | ![]() |
Out[6]= | ![]() |