[programming] minor text changes
This commit is contained in:
parent
772eef46f5
commit
04029ca07b
@ -1031,7 +1031,7 @@ segment of data of a certain time span (the stimulus was on,
|
|||||||
\varcode{x} represent the measured data at the times in
|
\varcode{x} represent the measured data at the times in
|
||||||
\varcode{t}.
|
\varcode{t}.
|
||||||
\item Use logical indexing to select those values that have been
|
\item Use logical indexing to select those values that have been
|
||||||
recorded in the time span form 5--6\,s.
|
recorded in the time span from 5--6\,s.
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
@ -1095,7 +1095,7 @@ ans =
|
|||||||
Generally, a program is executed line by line from top to
|
Generally, a program is executed line by line from top to
|
||||||
bottom. Sometimes this is not the desired behavior, or the other way
|
bottom. Sometimes this is not the desired behavior, or the other way
|
||||||
round, it is needed to skip certain parts or execute others
|
round, it is needed to skip certain parts or execute others
|
||||||
repeatedly. High-level programming languages like \matlab{} offer
|
repeatedly. High-level programming languages such as \matlab{} offer
|
||||||
statements that allow to manipulate the control flow. There are two
|
statements that allow to manipulate the control flow. There are two
|
||||||
major classes of such statements:
|
major classes of such statements:
|
||||||
|
|
||||||
@ -1120,7 +1120,7 @@ x =
|
|||||||
120
|
120
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
|
||||||
This kind of program is fine but it is rather repetitive. The only
|
This kind of program solves the taks but it is rather repetitive. The only
|
||||||
thing that changes is the increasing factor. The repetition of such
|
thing that changes is the increasing factor. The repetition of such
|
||||||
very similar lines of code is bad programming style. This is not only
|
very similar lines of code is bad programming style. This is not only
|
||||||
a matter of taste but there are severe drawbacks to this style:
|
a matter of taste but there are severe drawbacks to this style:
|
||||||
@ -1136,7 +1136,7 @@ a matter of taste but there are severe drawbacks to this style:
|
|||||||
repetitions. It is easy to forget a single change.
|
repetitions. It is easy to forget a single change.
|
||||||
\item Readability: repetitive code is terrible to read and to
|
\item Readability: repetitive code is terrible to read and to
|
||||||
understand. (I) one tends to skip repetitions (its the same,
|
understand. (I) one tends to skip repetitions (its the same,
|
||||||
anyways) and misses the essential change. (II), the duplication of
|
anyway) and misses the essential change. (II), the duplication of
|
||||||
code leads to long and hard-to-parse programs.
|
code leads to long and hard-to-parse programs.
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
All imperative programming languages offer a solution: the loop. It is
|
All imperative programming languages offer a solution: the loop. It is
|
||||||
@ -1146,7 +1146,7 @@ used whenever the same commands have to be repeated.
|
|||||||
\subsubsection{The \code{for} --- loop}
|
\subsubsection{The \code{for} --- loop}
|
||||||
The most common type of loop is the \codeterm{for-loop}. It
|
The most common type of loop is the \codeterm{for-loop}. It
|
||||||
consists of a \codeterm[Loop!head]{head} and the
|
consists of a \codeterm[Loop!head]{head} and the
|
||||||
\codeterm[Loop!body]{body}. The head defines how often the code of the
|
\codeterm[Loop!body]{body}. The head defines how often the code in the
|
||||||
body is executed. In \matlab{} the head begins with the keyword
|
body is executed. In \matlab{} the head begins with the keyword
|
||||||
\code{for} which is followed by the \codeterm{running variable}. In
|
\code{for} which is followed by the \codeterm{running variable}. In
|
||||||
\matlab{} a for-loop always operates on vectors. With each
|
\matlab{} a for-loop always operates on vectors. With each
|
||||||
@ -1191,7 +1191,7 @@ while x == true % head with a Boolean expression
|
|||||||
% execute this code if the expression yields true
|
% execute this code if the expression yields true
|
||||||
end
|
end
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
|
||||||
\begin{exercise}{factorialWhileLoop.m}{}
|
\begin{exercise}{factorialWhileLoop.m}{}
|
||||||
Implement the factorial of a number \varcode{n} using a \code{while}
|
Implement the factorial of a number \varcode{n} using a \code{while}
|
||||||
-- loop.
|
-- loop.
|
||||||
@ -1201,7 +1201,7 @@ end
|
|||||||
\begin{exercise}{neverendingWhile.m}{}
|
\begin{exercise}{neverendingWhile.m}{}
|
||||||
Implement a \code{while}--loop that is never-ending. Hint: the body
|
Implement a \code{while}--loop that is never-ending. Hint: the body
|
||||||
is executed as long as the Boolean expression in the head is
|
is executed as long as the Boolean expression in the head is
|
||||||
true. You can escape the loop by pressing \keycode{Ctrl+C}.
|
\code{true}. You can escape the loop by pressing \keycode{Ctrl+C}.
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user