Hello all, I am having confusion with the IF statement because I have seen that in other languages there is ELSEIF or ELIF, and when searching for something similar in Mathematica didn’t find it, it is for this reason that I am turning to you to ask them if there is something similar to ELSEIF or ELIF or definitely should i use WHICH, I share with you some images of what I am talking about. By its aid, a thousand thanks,greetings
Which is essentially synonymous with an elseif construct in other languages. This should probably be clarified in the documentation. If you want to add a final else statement, set the last condition to True, like this:
In[1]:= x = 5; Which[x == 1, 10, x == 2, 20, x == 3, 30, True, 100]
Out[1]= 100
If you want to test different patterns against a single value, Switch might be more elegant. See below:
Many thanks to Daniel Lichtblau and Jesse Friedman for their replies, the problem i have is that I do not know how to move from what is done in Modula-2 to Mathematica, i.e. i have problems to separate it into parts to do so using WHICH the other is made and verified. If someone can help me appreciate greatly.
Annex in a document the code that i have Modula-2 and also the translation attempt to Mathematica that i made. What causes me conflict is the ELSIF , because I do not know how to have fun to Which