[translation] loopses done
This commit is contained in:
parent
91564a7ef9
commit
2ad2dc3dc4
@ -1019,7 +1019,9 @@ major classes of such statements:
|
|||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
|
||||||
\subsection{Loops}
|
\subsection{Loops}
|
||||||
As the name already suggests loops are used to execute the same parts of the code repeatedly. In one of the earlier exercises the faculty of five has been calculated as depicted in listing~\ref{facultylisting}.
|
As the name already suggests loops are used to execute the same parts
|
||||||
|
of the code repeatedly. In one of the earlier exercises the faculty of
|
||||||
|
five has been calculated as depicted in listing~\ref{facultylisting}.
|
||||||
|
|
||||||
\begin{lstlisting}[caption={Calculation of the faculty of 5 in five steps}, label=facultylisting]
|
\begin{lstlisting}[caption={Calculation of the faculty of 5 in five steps}, label=facultylisting]
|
||||||
>> x = 1;
|
>> x = 1;
|
||||||
@ -1089,54 +1091,55 @@ purpose. The \code{for} loop is closed with the keyword
|
|||||||
|
|
||||||
\subsubsection{The \varcode{while} --- loop}
|
\subsubsection{The \varcode{while} --- loop}
|
||||||
|
|
||||||
Eine weiterer Schleifentyp, der weniger h\"aufig eingesetzt wird, ist
|
The \code{while}--loop is the second type of loop that is available in
|
||||||
die \code{while}-Schleife. Auch sie hat ihre Entsprechungen in fast
|
almost all programming languages. Other, than the \code{for} -- loop,
|
||||||
allen Programmiersprachen. \"Ahnlich zur \code{for} Schleife wird
|
that iterates with the running variable over a vector, the while loop
|
||||||
auch hier der in der Schleife definierte Programmcode iterativ
|
uses a Boolean expression to determine when to execute the code in
|
||||||
ausgef\"uhrt. Der Schleifenkopf beginnt mit dem Schl\"usselwort
|
it's body. The head of the loop starts with the keyword \code{while}
|
||||||
\code{while} gefolgt von einem booleschen Ausdruck. Solange dieser zu
|
that is followed by a Boolean expression. If this can be evaluated to
|
||||||
\code{true} ausgewertet werden kann, wird der Code im
|
true, the code in the body is executed. The loop is closed with an
|
||||||
Schleifenk\"orper ausgef\"uhrt. Die Schleife wird mit dem
|
\code{end}.
|
||||||
Schl\"usselwort \code{end} beendet.
|
|
||||||
|
\begin{lstlisting}[caption={Basic structure of a \code{while} loop.}, label=whileloop]
|
||||||
|
while x == true % head with a Boolean expression
|
||||||
\begin{lstlisting}[caption={Grundstruktur einer \varcode{while} Schleife.}, label=whileloop]
|
% execute this code if the expression yields true
|
||||||
while x == true
|
|
||||||
% fuehre diesen sinnvollen Code aus ...
|
|
||||||
end
|
end
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
|
||||||
\begin{exercise}{facultyWhileLoop.m}{}
|
\begin{exercise}{facultyWhileLoop.m}{}
|
||||||
Implementiere die Fakult\"at mit einer \code{while}-Schleife.
|
Implement the faculty of a number \varcode{n} using a \code{while}
|
||||||
|
-- loop.
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
|
|
||||||
\begin{exercise}{neverendingWhile.m}{}
|
\begin{exercise}{neverendingWhile.m}{}
|
||||||
Implementiere eine \code{while}-Schleife, die unendlich
|
Implement a \code{while}--loop that is never-ending. Hint: the body
|
||||||
l\"auft. Tipp: wenn der boolesche Ausdruck hinter dem \code{while}
|
is executed as long as the Boolean expression in the head is
|
||||||
zu wahr ausgewertet wird, wird die Schleife weiter ausgef\"uhrt.
|
true. You can escape the loop by pressing \keycode{Ctrl+C}.
|
||||||
Das Programm kann mit \keycode{Ctrl+C} abgebrochen werden.
|
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
|
|
||||||
\subsubsection{Vergleich \varcode{for} -- und \varcode{while}--Schleife}
|
\subsubsection{Comparison \varcode{for} -- and \varcode{while} -- loop}
|
||||||
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item Beide f\"uhren den Code im Schleifenk\"orper iterativ aus.
|
\item Both execute the code in the body iterative.
|
||||||
\item Der K\"orper einer \code{for} Schleife wird mindestens 1 mal
|
\item When using a \code{for} -- loop the body of the loop is executed
|
||||||
betreten (au{\ss}er wenn der Vektor im Schleifenkopf leer ist).
|
at least once (except when the vector used in the head is empty).
|
||||||
\item Der K\"orper einer \code{while} Schleife wird nur dann betreten,
|
\item In a \code{while} -- loop, the body is not necessarily
|
||||||
wenn die Bedingung im Kopf \code{true} ist. \\$\rightarrow$ auch
|
executed. It is entered only if the Boolean expression in the head
|
||||||
``Oben-abweisende'' Schleife genannt.
|
yields true.
|
||||||
\item Die \code{for} Schleife eignet sich f\"ur F\"alle in denen f\"ur
|
\item The \code{for} -- loop is best suited for cases in which the
|
||||||
jedes Element eines Vektors der Code ausgef\"uhrt werden soll.
|
elements of a vector have to be used for a computation or when the
|
||||||
\item Die \code{while} Schleife ist immer dann gut, wenn nicht klar
|
number of iterations is known.
|
||||||
ist wie h\"aufig etwas ausgef\"uhrt werden soll. Sie ist
|
\item The \code{while} -- loop is best suited for cases when it is not
|
||||||
speichereffizienter.
|
known in advance how often a certain piece of code has to be
|
||||||
\item Jedes Problem kann mit beiden Typen gel\"ost werden.
|
executed.
|
||||||
|
\item Any problem that can be solved with one type can also be solve
|
||||||
|
with the other type of loop.
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
|
|
||||||
\subsection{Bedingte Anweisungen und Verzweigungen}
|
\subsection{Conditional expressions}
|
||||||
|
|
||||||
Bedingte Anweisungen und Verzweigungen sind Kontrollstrukturen, die
|
Bedingte Anweisungen und Verzweigungen sind Kontrollstrukturen, die
|
||||||
regeln, dass der in ihnen eingeschlossene Programmcode nur unter
|
regeln, dass der in ihnen eingeschlossene Programmcode nur unter
|
||||||
|
Reference in New Issue
Block a user