Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
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 True; otherwise, it 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]= | ![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License