If-then statement - Mendix Forum

If-then statement


Hi community,


I would love to have an 'if' / 'if-then' only statement in my 'Change' actions so I can eliminate redundant expressions like the part with 'else':


if $Object/value = 0    

     then $variablePrice

else $Object/value           //So if false I don't want to do anything, but I need to put 'else' here, so I'll change you to what you are/were. 


So the below expression without the StudioPro errors would be awesome:


if $Object/value = 0    

     then $variablePrice


This could:

- improve speed and readability while developing

- reduce errors when you don't want to change a value when false

- ease of use


Sure I can model this al out using splits, but in larger Change actions with multiple attributes that are changed,  this can result in lots of extra splits and smaller change actions. 



Source: The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics) (oracle.com)



2 answers

Having hidden behavior does not improve "readability" in my opinion. Expressions must always have a result no matter what path they take. I am strongly against this change.


My general advise is always to prevent (hidden) logic in the 'Change object' at all, but to explicitly model it using a variable or splits. However, with a simple check like you propose this would definitely make things nice and compact!