diff --git a/3 - Functional Programming/1.2 - Control Statements.tex b/3 - Functional Programming/1.2 - Control Statements.tex index b53929a..6501f15 100644 --- a/3 - Functional Programming/1.2 - Control Statements.tex +++ b/3 - Functional Programming/1.2 - Control Statements.tex @@ -1,8 +1,38 @@ - +Control statements are almost exactly as they sound, statements that control our programs. +Well, they control the flow of our code. +With control statements we can change the course of our programs based on various conditions. \subsection{If Statements} +If stataments allow us to execute a given block of code based on a given condition. +There are three main parts to an if statement \pigVal{if}, the \pigVal{conditional} and a \pigVal{code block}. + + +\begin{lstlisting}[caption={If Statement}] +name = ``brett'' + +if( name == ``brett'' ) + print ``Name is brett'' +\end{lstlisting} + +In this simple example the code block \pigOut{print ``Name is brett''} will only execute if the conditional \pigOut{name == ``brett''} is true. +So the output of this code will be \pigOut{Name is brett}. + +\begin{lstlisting}[caption={False If Statement}] +name = ``brett'' + +if( name == ``john'' ) + print ``Name is john'' +\end{lstlisting} + +In this example there will be no output, this is because the conditional \pigOut{name == ``john''} equates to false so the code block \pigOut{print ``Name is john''} will never get executed. \subsection{If-Else Statements} +If statements are great and help us execute portions of our code based on the values of other variables, including based on input from users. +But what if the condition of the if statement equates to false? +With if statements we can append an else statement and a block of code to the end of an if statement that will get called if the if statement is false. + + +\subsection{Else If Statements} \subsection{For Loops} diff --git a/Programming In General.pdf b/Programming In General.pdf index 7d4245f..0697149 100644 Binary files a/Programming In General.pdf and b/Programming In General.pdf differ diff --git a/Programming In General.tex b/Programming In General.tex index 1f9f0fa..cd7e808 100644 --- a/Programming In General.tex +++ b/Programming In General.tex @@ -151,6 +151,10 @@ Brett \textsc{Langdon} \input{"./3 - Functional Programming/1.2 - Control Statements"} \vfill \pagebreak +\section{Control Statements~} +\input{"./3 - Functional Programming/1.2 - Control Statements~"} +\vfill +\pagebreak \section{Functions} \input{"./3 - Functional Programming/1.3 - Functions"} \vfill