Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline Jadalbert  
#1 Posted : 12 July 2019 14:26:36(UTC)
Jadalbert

Rank: Newbie

Groups: Registered
Joined: 19/11/2013(UTC)
Posts: 9
Poland

Hi,
I have the question like this:
Is it possible to obtain a result depending on whether the variable belongs to the collection?

I mean the construction:

if x "belongs to" {1, 2, 4, 8} then x=0 else x=111
or even
if x "belongs to" {1, 2, 4, 8} else if x "belongs to {33, 45, 11) then x=99 else x=111

Thanks for an any response.
Jadalbert
Crazy
Offline alyles  
#2 Posted : 12 July 2019 15:27:29(UTC)
alyles


Rank: Advanced Member

Groups: Registered
Joined: 23/03/2016(UTC)
Posts: 191
United States

Was thanked: 65 time(s) in 41 post(s)
Perhaps something like this?
Untitled.png
elementsbelongs.sm (5kb) downloaded 8 time(s).

Edited by user 12 July 2019 15:31:11(UTC)  | Reason: Not specified

Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
thanks 1 user thanked alyles for this useful post.
on 12/07/2019(UTC)
Offline Jean Giraud  
#3 Posted : 13 July 2019 16:45:58(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 3,887
Canada

Was thanked: 699 time(s) in 547 post(s)
Originally Posted by: Jadalbert Go to Quoted Post
I have the question like this:
Is it possible to obtain a result depending on whether the variable belongs to the collection?

This is too vague for real answer.
Yes, you can locate elements of an array that belongs as well to another array.
Please, visit an extensive example, posted next few minutes:
"Locate in array"
In simple one array is much simpler, please let know if desired.

Cheers.

Offline Jadalbert  
#4 Posted : 13 July 2019 17:10:28(UTC)
Jadalbert

Rank: Newbie

Groups: Registered
Joined: 19/11/2013(UTC)
Posts: 9
Poland

Thank You both for help. I tested both example and it works. But I dont understand how can I add new line to method (function) cases()? If it is the function cases(), may be I'm wrong. I mean:
x := {1 if ...; 2 otherwise
Offline Jean Giraud  
#5 Posted : 14 July 2019 01:29:29(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 3,887
Canada

Was thanked: 699 time(s) in 547 post(s)
Originally Posted by: Jadalbert Go to Quoted Post
But I don't understand how can I add new line to method (function) cases()?

... like this
once you have if/otherwise [Cases], click right hand most place holder,
coma twice for one more if... again coma twice like before, DIY.
Cheers.

Offline Jadalbert  
#6 Posted : 15 July 2019 14:29:29(UTC)
Jadalbert

Rank: Newbie

Groups: Registered
Joined: 19/11/2013(UTC)
Posts: 9
Poland

Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: Jadalbert Go to Quoted Post
But I don't understand how can I add new line to method (function) cases()?

... like this
once you have if/otherwise [Cases], click right hand most place holder,
coma twice for one more if... again coma twice like before, DIY.
Cheers.



Ok, it works. But, I must use SEMICOLON twice. May be it is the same as coma (or comma) in real english. Im from Poland and my English is from school.
Anyway - thank You for help.
Jadalbert
Offline Davide Carpi  
#7 Posted : 15 July 2019 14:41:38(UTC)
Davide Carpi


Rank: Advanced Member

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

Was thanked: 1105 time(s) in 726 post(s)
Originally Posted by: Jadalbert Go to Quoted Post
But, I must use SEMICOLON twice.


That's because the more correct answer about arguments or decimal separators would be "press your argument separator" or "press your decimal separtor", since you can customize them in Tools > Options Good
If you like my plugins please consider a donation to SMath Studio; for personal contributions to me: paypal.me/dcprojects
Users browsing this topic
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.