[translation] if done
This commit is contained in:
parent
306c1197d4
commit
8eaae72262
@ -1141,49 +1141,49 @@ end
|
|||||||
|
|
||||||
\subsection{Conditional expressions}
|
\subsection{Conditional expressions}
|
||||||
|
|
||||||
Bedingte Anweisungen und Verzweigungen sind Kontrollstrukturen, die
|
The conditional expression are used to control that the enclosed code
|
||||||
regeln, dass der in ihnen eingeschlossene Programmcode nur unter
|
is only executed under a certain condition.
|
||||||
bestimmten Bedingungen ausgef\"uhrt wird.
|
|
||||||
|
\subsubsection{The \varcode{if} -- statement}
|
||||||
\subsubsection{Die \varcode{if} -- Anweisung}
|
|
||||||
|
The most prominent representative of the conditional expressions is
|
||||||
Am h\"aufigsten genutzter Vertreter ist die \code{if} -
|
the \code{it} statement (sometimes also called \code{if - else}
|
||||||
Anweisung. Sie wird genutzt um Programmcode nur unter bestimmten
|
statement). It constitutes a kind of branching point. It allows to
|
||||||
Bedingungen auszuf\"uhren.
|
control which code is executed.
|
||||||
|
|
||||||
Der Kopf der \code{if} - Anweisung beginnt mit dem Schl\"usselwort \code{if}
|
Again, the statement consists of the head and the body. The head
|
||||||
welches von einem booleschen Ausdruck gefolgt wird. Wenn
|
begins with the keyword \code{if} followed by a Boolean expression
|
||||||
dieser zu \code{true} ausgewertet werden kann, wird der Code im
|
that controls whether or not the body is entered. Optionally the body
|
||||||
K\"orper der Anweisung ausgef\"uhrt. Optional k\"onnen weitere
|
can be either ended by the \code{end} keyword or followed by
|
||||||
Bedingungen mit dem Schl\"usselwort \code{elseif} folgen. Ebenfalls
|
additional statements \code{elseif}, which allows to add another
|
||||||
optional ist die Verwendung eines finalen \code{else} - Falls. Dieser
|
Boolean expression and to catch a certain condition or the \code{else}
|
||||||
wird immer dann ausgef\"uhrt wenn alle vorherigen Bedingungen nicht
|
the provide a default case. The last body of the \code{if - elseif -
|
||||||
erf\"ullt wurden. Die \code{if} - Anweisung wird mit \code{end}
|
else} statement has to be finished with the \code{end}
|
||||||
beendet. Listing \ref{ifelselisting} zeigt den Aufbau einer
|
(listing~\ref{ifelselisting}).
|
||||||
\code{if} - Anweisung.
|
|
||||||
|
\begin{lstlisting}[label=ifelselisting, caption={Structure of an \code{if} statement.}]
|
||||||
|
if x < y % head
|
||||||
\begin{lstlisting}[label=ifelselisting, caption={Grundger\"ust einer \varcode{if} Anweisung.}]
|
% body I, executed only if x < y
|
||||||
if x < y
|
|
||||||
% fuehre diesen code aus wenn x < y
|
|
||||||
elseif x > y
|
elseif x > y
|
||||||
% etwas anderes soll getan werden fuer x > y
|
% body II, executed only if the first condition did not match and x > y
|
||||||
else
|
else
|
||||||
% wenn x == y, wieder etwas anderes
|
% body III, executed only if the previous conditions did not match
|
||||||
end
|
end
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
|
||||||
\begin{exercise}{ifelse.m}{}
|
\begin{exercise}{ifelse.m}{}
|
||||||
Ziehe eine Zufallszahl und \"uberpr\"ufe mit einer geeigneten \code{if} Anweisung, ob sie
|
Draw a random number and check with an appropriate \code{if}
|
||||||
|
statement whether it is
|
||||||
\begin{enumerate}
|
\begin{enumerate}
|
||||||
\item kleiner als 0.5 ist.
|
\item less than 0.5.
|
||||||
\item kleiner oder gr\"o{\ss}er-gleich 0.5 ist.
|
\item less or greater-or-equal 0.5.
|
||||||
\item (i) kleiner als 0.5, (ii) gr\"o{\ss}er oder gleich 0.5 aber kleiner
|
\item (i) less than 0.5, (ii) greater-or-equal 0.5 but less than
|
||||||
als 0.75 oder (iii) gr\"o{\ss}er oder gleich 0.75 ist.
|
0.75 or (iii) greater-or-equal to 0.75.
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
\subsubsection{Die \varcode{switch} -- Verzweigung}
|
\subsubsection{The \varcode{switch} -- statement}
|
||||||
|
|
||||||
|
|
||||||
Die \code{switch} Verzweigung wird eingesetzt wenn mehrere F\"alle
|
Die \code{switch} Verzweigung wird eingesetzt wenn mehrere F\"alle
|
||||||
auftreten k\"onnen, die einer unterschiedlichen Behandlung bed\"urfen.
|
auftreten k\"onnen, die einer unterschiedlichen Behandlung bed\"urfen.
|
||||||
|
Reference in New Issue
Block a user