element belongs to a collection

element belongs to a collection - collections - Сообщения

#1 Опубликовано: 12.07.2019 08:26:36
Jadalbert

Jadalbert

0 сообщений из 17 понравились пользователям.

Группа: User

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
#2 Опубликовано: 12.07.2019 09:27:29
Arie

Arie

93 сообщений из 285 понравились пользователям.

Группа: User

Perhaps something like this?
Untitled.png
elementsbelongs.sm (4 КиБ) скачан 31 раз(а).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
1 пользователям понравился этот пост
frapuano 12.07.2019 16:24:00
#3 Опубликовано: 13.07.2019 10:45:58
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

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.

#4 Опубликовано: 13.07.2019 11:10:28
Jadalbert

Jadalbert

0 сообщений из 17 понравились пользователям.

Группа: User

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
#5 Опубликовано: 13.07.2019 19:29:29
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

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.

#6 Опубликовано: 15.07.2019 08:29:29
Jadalbert

Jadalbert

0 сообщений из 17 понравились пользователям.

Группа: User

Wrote

Wrote

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
#7 Опубликовано: 15.07.2019 08:41:38
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: Moderator

Wrote

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
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений