Branching with if and else in Modelica is straightforward.
Note that in Modelica, you don’t need parentheses around conditions, but the then keyword is required after the condition. The end if is also required to close the if statement.
To run this Modelica model, you would typically use a Modelica simulation environment. The output would be similar to:
Modelica doesn’t have a direct equivalent to the ternary operator found in some other languages, so you’ll need to use a full if statement even for basic conditions.
It’s important to note that Modelica is primarily used for modeling and simulation of physical systems, so the way conditionals are used might differ from procedural programming languages. In Modelica, equations are solved simultaneously rather than executed sequentially.