Skip to content

Commit

Permalink
Clarify elsewhen (modelica#3217)
Browse files Browse the repository at this point in the history
* Clarify elsewhen
Closes modelica#3216

* Update chapters/equations.tex
  • Loading branch information
HansOlsson committed Jul 12, 2022
1 parent a9b3f31 commit 96ddf78
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions chapters/equations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,33 @@ \subsubsection{Single Assignment Rule Applied to When-Equations}\label{applicati
\begin{lstlisting}[language=modelica]
model WhenPriority
Boolean close; // Correct model: close defined by two equations!
algorithm
equation
$\ldots$
when condition1 then
close := true;
close = true;
elsewhen condition2 then
close := false;
close = false;
end when;
$\ldots$
end WhenPriority;
\end{lstlisting}
An alternative to \lstinline!elsewhen! (in an equation or algorithm) is to use an algorithm with multiple \lstinline!when!-statements.
However, both statements will be executed if both conditions become \lstinline!true! at the same time.
Therefore they must be in reverse order to preserve the priority, and any side-effect would require more care.
\begin{lstlisting}[language=modelica]
model WhenPriorityAlg
Boolean close; // Correct model: close defined by two when-statements!
algoritmh
$\ldots$
when condition2 then
close := false;
end when;
when condition1 then
close := true;
end when;
$\ldots$
end WhenPriorityAlg;
\end{lstlisting}
\end{nonnormative}
\end{itemize}

Expand Down

0 comments on commit 96ddf78

Please sign in to comment.