[translation] loopses done

This commit is contained in:
Jan Grewe 2016-10-13 10:19:57 +02:00
parent 91564a7ef9
commit 2ad2dc3dc4

View File

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