From d98f9d041d7fca7d526d924f6cc46cd73c7b80fd Mon Sep 17 00:00:00 2001 From: Hans Olsson Date: Wed, 2 Oct 2019 10:08:17 +0200 Subject: [PATCH] Update for-statement to refer to for-equation and clarify evaluation. (#2391) * Update for-statement to refer to for-equation and clarify evaluation. Closes #2205 Closes #2208 --- chapters/equations.tex | 13 ++++++++----- chapters/statements.tex | 8 ++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/chapters/equations.tex b/chapters/equations.tex index 0c23b684c..24f9a278a 100644 --- a/chapters/equations.tex +++ b/chapters/equations.tex @@ -103,15 +103,17 @@ \subsection{For-Equations -- Repetitive Equation Structures}\doublelabel{for-equ for IDENT in expression loop \end{lstlisting} -The \lstinline!expression! of a for-equation shall be a vector expression. It is -evaluated once for each for-equation, and is evaluated in the scope +\subsubsection{Explicit Iteration Ranges of For-Equations}\doublelabel{explicit-iteration-ranges-of-for-equations} +The \lstinline!expression! of a for-equation shall be a vector expression, +where more general array expressions are treated as vector of vectors or vector of matrices. +It is evaluated once for each for-equation, and is evaluated in the scope immediately enclosing the for-equation. The expression of a for-equation shall be a parameter expression. The iteration range of a for-equation can also be specified as Boolean or as an enumeration type, see \autoref{types-as-iteration-ranges} for more information. The loop-variable (\lstinline!IDENT!) is in scope -inside the loop-construct and shall not be assigned to. The -loop-variable has the same type as the type of the elements of the -vector expression. +inside the loop-construct and shall not be assigned to. +For each element of the evaluated vector expression, in the normal order, the loop-variable +gets the value of that element and that is used to evaluate the body of the for-loop. {[}\emph{Example}: \begin{lstlisting}[language=modelica] @@ -136,6 +138,7 @@ \subsection{For-Equations -- Repetitive Equation Structures}\doublelabel{for-equ \end{lstlisting} {]} + \subsubsection{Implicit Iteration Ranges of For-Equations}\doublelabel{implicit-iteration-ranges-of-for-equations} The iteration range of a loop variable may sometimes be inferred from diff --git a/chapters/statements.tex b/chapters/statements.tex index 1478ba424..3e658557d 100644 --- a/chapters/statements.tex +++ b/chapters/statements.tex @@ -193,12 +193,8 @@ \subsection{For-statement}\doublelabel{for-statement} \begin{lstlisting}[language=modelica] for IDENT in expression loop \end{lstlisting} -The \lstinline!expression! of a for-statement shall be a vector expression. It is -evaluated once for each for-statement, and is evaluated in the scope -immediately enclosing the for-statement. The loop-variable (\lstinline!IDENT!) is in -scope inside the loop-construct and shall not be assigned to. The -loop-variable has the same type as the type of the elements of the -vector expression. +The rules for for-statements are the same as for for-expressions in \autoref{explicit-iteration-ranges-of-for-equations} - +except that the \lstinline!expression! of a for-statement is not restricted to a parameter-expression. {[}\emph{Example}: