Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline RegRetired  
#1 Posted : 09 May 2024 08:35:48(UTC)
RegRetired


Rank: Advanced Member

Groups: Registered
Joined: 03/06/2023(UTC)
Posts: 57
Man
United States

Was thanked: 1 time(s) in 1 post(s)
Help would be appreciated. I cannot make a chain of if-else statements equal to the cases formalism. What am I missing. I have tried the less than or equal only in the cases formalism. That didn't work either. The if-else results are correct, the cases formalism is not correct.

IF ELSE VERSUS CASES FORMALISM.sm (13kb) downloaded 4 time(s).

Thanks for any help.
Reg
Reg Curry
Loveland, CO

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline RegRetired  
#2 Posted : 09 May 2024 08:43:15(UTC)
RegRetired


Rank: Advanced Member

Groups: Registered
Joined: 03/06/2023(UTC)
Posts: 57
Man
United States

Was thanked: 1 time(s) in 1 post(s)
Oops sorry. I had errors in my formulas. Here is the corrected version where the two formalisms do agree.

IF ELSE VERSUS CASES FORMALISM.sm (13kb) downloaded 6 time(s).

Sorry Blush
Reg Curry
Loveland, CO
Offline Davide Carpi  
#3 Posted : 09 May 2024 22:09:52(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,654
Man
Italy
Location: Italy

Was thanked: 1340 time(s) in 879 post(s)
No problem, when possible, better ask.

I would point out that currently you can avoid the nested if/else and convert it in if/else if/else (if you wish), simply adding more arguments. As side note if you delete an argument from the default if/else, you'll get an if without else.

IF ELSE VERSUS CASES FORMALISM(2).sm (17kb) downloaded 14 time(s).


Also, since the topic is about if/else vs cases, I would like to highlight that cases has a different coding approach to evaluate in some situations where if/else is not allowed to; this feature comes at the cost that you shouldn't make assignments ( : ) inside its arguments, while in if/else you can safely build block of codes inside it using the line function (see here and here for examples).

Edited by user 10 May 2024 10:15:37(UTC)  | Reason: small clarification

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline RegRetired  
#4 Posted : 10 May 2024 07:02:59(UTC)
RegRetired


Rank: Advanced Member

Groups: Registered
Joined: 03/06/2023(UTC)
Posts: 57
Man
United States

Was thanked: 1 time(s) in 1 post(s)
Davide,
Thanks much. Very helpful as always.
Reg
Reg Curry
Loveland, CO
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.