Skip to main content
February 22, 2024
Question

Unintuitive If() behaviour

  • February 22, 2024
  • 5 replies
  • 1 view
Current Behaviour:
a!localVariables(
Â%A0 local!test: {},
Â%A0 if(
Â%A0 Â%A0 condition: local!test > 0,
Â%A0 Â%A0 valueIfTrue: {
Â%A0 Â%A0 Â%A0 "My First Message",
Â%A0 Â%A0 Â%A0 "My second Message",
Â%A0 Â%A0 Â%A0 "My third message"
Â%A0 Â%A0 },
Â%A0 Â%A0 valueIfFalse: "My false Message"
Â%A0 )
)
Given the above code when the local!test value is {1} the output is {"My First Message"}
when the local!test value is {1,2} the output is {"My First Message", "My second Message"}
when the local!test value is {1,2,3,4} the output is {"My First Message", "My second Message", "My third message", "My First Message"}
If you set the condition to be local!test < 0 you will see similar unintuitive behaviour.
Expected behaviour: an error to be thrown stating that you can not do a comparison between a value and a list.

5 replies

april.schuppel
February 22, 2024

Hi [mention:35af83396195480d93e2316c1a6675ff:e9ed411860ed4f2ba0265705b8793d05] ,

The if() function docs explain this behavior: "However, if the value parameters have shorter lists than the condition, the index is not maintained. Instead, each item is returned in order (and repeats if necessary)."

deans4069Author
February 22, 2024

Should this be updated since condition can be a list of boolean and not just the data type boolean?

april.schuppel
February 22, 2024

Interesting point - I can bring it up with the docs team!