How can I shorten these two If expressions into one
variable="hello";
If[variable=="hi", Print["hi there"]];
If[variable=="hello", Print["hi there"]];
Longhand shortening:
If[variable=="hello" || variable=="hi", Print["hi there"]];
to something like this:
If[variable=={"hello","hi"}, Print["hi there"]];
MemberQ[{"hello","hi"}, variable]– Coolwater May 04 '18 at 21:02WhichandSwitchmight be helpful. – Henrik Schumacher May 05 '18 at 06:49