if condition then
equation;
....
end;
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
end;
if time == 10 then // note the use of the equal operator ==
b = true; // equations to be executed if condition is true,
end;
1. | The output of the condition must be a boolean. |
Note
1. | Take care when using an 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. | There is also an if-then-else statement. |
3. | 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. |