From 8eaae722621ff4c7f368061a76fa68d5143f5d27 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Thu, 13 Oct 2016 10:37:58 +0200 Subject: [PATCH] [translation] if done --- programming/lecture/programming.tex | 64 ++++++++++++++--------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/programming/lecture/programming.tex b/programming/lecture/programming.tex index ff72eee..69547a6 100644 --- a/programming/lecture/programming.tex +++ b/programming/lecture/programming.tex @@ -1141,49 +1141,49 @@ end \subsection{Conditional expressions} -Bedingte Anweisungen und Verzweigungen sind Kontrollstrukturen, die -regeln, dass der in ihnen eingeschlossene Programmcode nur unter -bestimmten Bedingungen ausgef\"uhrt wird. - -\subsubsection{Die \varcode{if} -- Anweisung} - -Am h\"aufigsten genutzter Vertreter ist die \code{if} - -Anweisung. Sie wird genutzt um Programmcode nur unter bestimmten -Bedingungen auszuf\"uhren. - -Der Kopf der \code{if} - Anweisung beginnt mit dem Schl\"usselwort \code{if} -welches von einem booleschen Ausdruck gefolgt wird. Wenn -dieser zu \code{true} ausgewertet werden kann, wird der Code im -K\"orper der Anweisung ausgef\"uhrt. Optional k\"onnen weitere -Bedingungen mit dem Schl\"usselwort \code{elseif} folgen. Ebenfalls -optional ist die Verwendung eines finalen \code{else} - Falls. Dieser -wird immer dann ausgef\"uhrt wenn alle vorherigen Bedingungen nicht -erf\"ullt wurden. Die \code{if} - Anweisung wird mit \code{end} -beendet. Listing \ref{ifelselisting} zeigt den Aufbau einer -\code{if} - Anweisung. +The conditional expression are used to control that the enclosed code +is only executed under a certain condition. + +\subsubsection{The \varcode{if} -- statement} + +The most prominent representative of the conditional expressions is +the \code{it} statement (sometimes also called \code{if - else} +statement). It constitutes a kind of branching point. It allows to +control which code is executed. + +Again, the statement consists of the head and the body. The head +begins with the keyword \code{if} followed by a Boolean expression +that controls whether or not the body is entered. Optionally the body +can be either ended by the \code{end} keyword or followed by +additional statements \code{elseif}, which allows to add another +Boolean expression and to catch a certain condition or the \code{else} +the provide a default case. The last body of the \code{if - elseif - + else} statement has to be finished with the \code{end} +(listing~\ref{ifelselisting}). - -\begin{lstlisting}[label=ifelselisting, caption={Grundger\"ust einer \varcode{if} Anweisung.}] -if x < y - % fuehre diesen code aus wenn x < y +\begin{lstlisting}[label=ifelselisting, caption={Structure of an \code{if} statement.}] +if x < y % head + % body I, executed only if 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 - % wenn x == y, wieder etwas anderes + % body III, executed only if the previous conditions did not match end \end{lstlisting} \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} - \item kleiner als 0.5 ist. - \item kleiner oder gr\"o{\ss}er-gleich 0.5 ist. - \item (i) kleiner als 0.5, (ii) gr\"o{\ss}er oder gleich 0.5 aber kleiner - als 0.75 oder (iii) gr\"o{\ss}er oder gleich 0.75 ist. + \item less than 0.5. + \item less or greater-or-equal 0.5. + \item (i) less than 0.5, (ii) greater-or-equal 0.5 but less than + 0.75 or (iii) greater-or-equal to 0.75. \end{enumerate} \end{exercise} -\subsubsection{Die \varcode{switch} -- Verzweigung} +\subsubsection{The \varcode{switch} -- statement} + Die \code{switch} Verzweigung wird eingesetzt wenn mehrere F\"alle auftreten k\"onnen, die einer unterschiedlichen Behandlung bed\"urfen.