IF Commands

robin.tunley shared this question 6 years ago
Answered

Hello,


I have come across a few situations where I would like to make the value of a boolean variable dependent on some condition.

For example, suppose 'a' is a boolean variable and 'b' is a continuous variable from 0-1.


I want to script something along the lines of "If b<=0.5, a=true. Else, a = false".


Is there an easy way to do this?


Thanks,

Robin

Comments (2)

photo
1

Hi Robin


I want to script something along the lines of "If b<=0.5, a=true. Else, a = false".

As script: ("a" must be a exist free object, without dependencies), and must have the correct object-type (in this example: boolean)

SetValue[a, If[b<=0.5, true, false]]

or more short:

SetValue[a, b<=0.5] (the result of b<=0.5 is a boolean)


As dependet object: in algebra-view via input-line (if possible: the better option !)

a = If[b<=0.5, true, false]

or more short:

a = b<=0.5 (the result of b<=0.5 is a boolean)

This syntax can also be used in scripts, but it is not recommended (performance)


Greetings

Raymond

photo
1

Thanks so much! It's working now! :D

© 2022 International GeoGebra Institute