%%Nested Statements:
% Put a control statement (if, while, or for) inside of another control
% statement
% We can do this repeatedly

%We saw this briefly at the end of the while loop video, where there was
%an if statement inside of the while loop

%%Nested If Statements: If statements with if statements inside

%Syntax:

%if boolean_expression1
% if boolean_expression2
%   statements that execute if boolean_expression1 and boolean_expression2
%   is also true
% else
%   statements that execute if boolean_expression1 is true and
%   boolean_expression2 is false
% end
%else
% if boolean_expression3
%   statements that execute if boolean_expression1 is false and
%   boolean_expression3 is true
% else
%   statements that execute if boolean_expression1 is false and
%   boolean_expression3 is false
% end
%end

%Be careful with your end statements, there should be one per if. If you
%use good indentation, it's easier to track where this should be.

%If Statement example: Rock, paper, scissors
ROCK = 1; PAPER = 2; SCISSORS = 3;
p1 = ROCK; p2 = PAPER;
if p1 == ROCK
    if p2 == PAPER
        winner = 2;
    elseif p2 == SCISSORS
        winner = 1;
    else
        winner = 0;
    end

elseif p1 == PAPER
    if p2 == ROCK
        winner = 1;
    elseif p2 == SCISSORS
        winner = 2;
    else
        winner = 0;
    end

else % p1 == SCISSORS
    if p2 == ROCK
        winner = 2;
    elseif p2 == PAPER
        winner = 1;
    else
        winner = 0;
    end
end


%%Nested loops: A nested loop refers to putting one loop inside of another

%When executed, the first iteration of the outer loop triggers the inner
%loop, which runs to completion

%Then, the next iteration of the outer loop will start, which triggers the
%inner loop

%This process continues until the outer loop completes

%Nested loop example: Create a multiplication table
tablesize = 10;
multtable = zeros(tablesize);
for r=1:tablesize
  for c=1:tablesize
   multtable(r,c) = r*c;
  end
end
disp(multtable)

