Many conditions

Many conditions - Messages

#1 Posted: 8/17/2021 4:30:44 AM
Vasia

Vasia

0 likes in 17 posts.

Group: User

Здравствуйте.
Столкнулся со следующей проблемой: есть несколько условий, необходимо, чтобы при заданных значениях правильно бралось значение "а".
У меня почему-то игнорируется последнее условие - p0, то есть, в моем случае должно быть а=4, а программа выдает а=3.
Что я сделал не так?
example.jpg
proba.sm (11 KiB) downloaded 22 time(s).
#2 Posted: 8/17/2021 4:47:43 AM
sergio

sergio

115 likes in 329 posts.

Group: User

I don't see error in Smath as the reports indicated in the third "If" are all verified and therefore does not even pass to the fourth "IF". Maybe you should add that P0 = 0 (or something else).
P.S. I also point out an OR in the fourth "IF" while all the others are AND: it could be an oversight
sergio
#3 Posted: 8/17/2021 4:54:56 AM
Vasia

Vasia

0 likes in 17 posts.

Group: User

Wrote

I don't see error in Smath as the reports indicated in the third "If" are all verified and therefore does not even pass to the fourth "IF". Maybe you should add that P0 = 0 (or something else).
P.S. I also point out an OR in the fourth "IF" while all the others are AND: it could be an oversight
sergio



Спасибо, понял, что надо сделать - в первые три варианта прописал p0<100 и все заработало.
#4 Posted: 8/17/2021 11:30:24 AM
overlord

overlord

552 likes in 1332 posts.

Group: Moderator

Wrote

Спасибо, понял, что надо сделать - в первые три варианта прописал p0<100 и все заработало.


You don't have to describe p<100. Just re-order the if statements.
In original, third statement if condition gets true regardless of p.0 value.
When it gets the true value in if condition, it won't be looked for next if.
Moving the p.0 boolean check to first will make all conditions available to read.

You can use cases() for smaller, tidier and much readable if blocks.
Using nested if() and cases() will reduce the huge block of boolean.
Your φ.n - λ.n - h.q checks are same for all, nesting λ under it is possible.
And you can also use multiple boolean conditions. lele(),lelt(),gege(), etc.

Regards

proba_r1.sm (5 KiB) downloaded 26 time(s).

2021-08-17_17-29.png
#5 Posted: 8/18/2021 10:56:50 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Maths lele.sm (8 KiB) downloaded 22 time(s).
#6 Posted: 8/18/2021 11:44:26 AM
overlord

overlord

552 likes in 1332 posts.

Group: Moderator

You can even triple nest boolean checks.
0.5<=λ<=0.6 can be written as one cases().

Regards

2021-08-18_17-42.png
  • New Posts New Posts
  • No New Posts No New Posts