Doing more than one thing with if

mertkans shared this question 4 years ago
Answered

Hi, I want to do more than one thing when an if condition is true. For example if[a<10,SetValue[a,3] and SetValue[b,5],SetValue[a,10]]

Best Answer
photo

if[a<10,Repeat[1,SetValue[a,3], SetValue[b,5],SetValue[c,10]]]

Note: no If inside Repeat

or

If[a<10, Execute[{"SetValue[a,3]", "SetValue[b,5]","SetValue[c,10]"}] ]

Note: the commands must be in english

Comments (2)

photo
2

if[a<10,Repeat[1,SetValue[a,3], SetValue[b,5],SetValue[c,10]]]

Note: no If inside Repeat

or

If[a<10, Execute[{"SetValue[a,3]", "SetValue[b,5]","SetValue[c,10]"}] ]

Note: the commands must be in english

photo
1

Also If[a>b,{SetValue[b,5],SetValue[a,10]}] should work. In most cases I'd suggest to avoid Execute (as rami said, Execute requires English commands and makes the code harder to read).

© 2022 International GeoGebra Institute