%-------------------------------------------------------------------------------
% lecture7a
%-------------------------------------------------------------------------------
  clear
% more on
  more off
  clc
% echo on
  echo off
%-------------------------------------------------------------------------------
% more about selection statements
%
% example) swap values
 
  disp(['swapping values'])
  v1 = input('give me value1: ');
  v2 = input('give me value2: ');

  % swapping using a "temporary" variable
  % $tmp$ acts as a placeholder
  tmp = v1;
  v1  = v2;
  v2  = tmp;

  disp(['v1 now has v2 value: ' num2str(v1)])
  disp(['v2 now has v1 value: ' num2str(v2)])
  disp(['press any key to continue'])

  pause
  clc

% now, apply to problem: 
%   Find the maximum of stored value and input value
%   Keep the smaller value in variable called $min$

  % input
  disp(['finding a max value'])
  max = input('give me a value: ');
  val = input('give me another value: ');

  % testing and swapping
  if (val > max)
     min = max;
     max = val;
  else
     min = val;
  end

  % output
  min
  max

  % curiosity
  val       % what happens to $v1$? nothing
  clear val % if you want to erase $v1$
  % val     % now unassigned!

%-------------------------------------------------------------------------------
