If Then

Navigation:  Language Reference > Statements >

If Then

Previous pageReturn to chapter overviewNext page


if condition then





The simplest if statement evaluates a condition and performs the specified equation(s) if the condition is true. If the condition is not true, 20-sim ignores the equation(s).


b = false;

y = ramp(1);

u = -ramp(1);

if time > 5 then

 y = -ramp(1); // equations to be executed if condition is true,

 u = ramp(1); // these are not executed if condition is false


if time == 10 then // note the use of the equal operator ==

 b = true; // equations to be executed if condition is true,



1.The output of the condition must be a boolean.
2.If needed, always use the equal operator (==) in the condition.


1.Take care when using event functions in if-then-else statements. In if-then-else statements only the equations of the true parts are evaluated, so event functions may not always be triggered!
2.Equations within an if statement have to be written in the correct order of execution, i.e. they are not rewritten into a causal form but executed sequentially.