We are simply defining a Function that is used to sum the values of two numbers together and then printing \pigOut{The Sum Is:} followed by
the sum of the numbers.
By defining two Parameters \pigVar{x} and \pigVar{y} we are telling any users of the Function that they must supply two values into the Function.
The first example usage of \pigVar{Sum}, \pigVar{Sum( 5, 6 )} correctly calls the Function and will cause the program to output \pigOut{The Sum Is: 11}.
The Second example \pigVar{Sum( 12 )} will cause the program to fail because only one Parameter is given when two were defined.
\par
When a Function is called and Parameters are given, the values passed into the Function are assigned to variables, inside of the Functions Scope, with the
same name given in the Function definition.
In our example above the value \pigVal{5} is passed into the Function and assigned to the variable \pigVar{x} because both are the first value and first
Parameter.
\pigVal{6} is then assigned to \pigVar{y}.
\subsection{Returns}
We have just seen how we can use Parameters to pass values into Functions, but what if we want to pass values back out of Functions?
We would use a Return statement.
When using a Return statement you use \pigVar{return} followed by the values or variable you wish to return out of the Function.
\begin{lstlisting}[caption={Return Example}]
def Sum( x, y )
sum = x + y
return sum
MySum = Sum( 5, 6 )
print ``The Sum Is: `` + MySum
\end{lstlisting}
This program will output \pigOut{The Sum Is: 11}.
The Function is the same as before but this time we are using \pigVar{return} to push the value assigned to \pigVar{sum} back out of the Function.
We can then assigned the output of the Function \pigVar{Sum} to a variable \pigVar{MySum} which will be equal to whatever the value that is returned is,
in this case \pigVal{11}.
When using Return statements in Functions you can then think about using Functions in the same way as you would a raw value (like a number).
\par
When the Return statement is reached the Function stops executing and the value of the Return statement is returned.
So we can use Return statements similar in fashion to how Break statements are used to quickly stop the execution of a Function.
\begin{lstlisting}[caption={Return to Stop Function}]
def PrintHello( name ):
if name == ``Brett'':
return
print ``Hello `` + name
PrintHello( ``Brett'' )
PrintHello( ``James'' )
\end{lstlisting}
This example program will only output \pigOut{Hello James}, because when the value \pigVal{Brett} is passed into the Function
the If statement evaluates to \pigVal{True} and the Return statement causes the Function to exit and the \pigVar{print} statement is
never reached.
\par
A Function can also contain multiple Return statements.