%-------------------------------------------------------------------------------
% lecture7c
% not finished!
%-------------------------------------------------------------------------------
  clear
% more on
  more off
  clc
  echo on
% echo off
%-------------------------------------------------------------------------------
% Loops
% + repetition statements
% + Now show way of doing manual multiple values
% + used to repeat operations
% + major reason for computers in the first place!
%-------------------------------------------------------------------------------
% WHILE loop
% From $help while$
%
% WHILE  Repeat statements an indefinite number of times.
%    The general form of a WHILE statement is:
%  
%       WHILE expression
%          statements
%       END
%  
%   The statements are executed while the real part of the expression
%   has all non-zero elements. The expression is usually the result of
%   expr rop expr where rop is ==, <, >, <=, >=, or ~=.
% 
%   The BREAK statement can be used to terminate the loop prematurely.
%-------------------------------------------------------------------------------
pause
clc
% example) count numbers from 1 to n

  x = 0; % x "so far"
  stop = input('enter stopping value n: ');
   
  % note:
  % variables that generalize a program $stop$ are called
  % NAMED CONSTANTS -- use them in as many palces as you can

  % output column of values from 1 to $stop$

  while (x < stop) 
    x = x + 1 % increment x by 1
    pause
  end

  x % what's x when loop ends?
%-------------------------------------------------------------------------------
% example) count numbers from 1 to n
%          this time, store the numbers in an array

  x = 0; % x "so far"
  stop = input('enter stopping value n: ');
   
  % note:
  % variables that generalize a program $stop$ are called
  % NAMED CONSTANTS -- use them in as many palces as you can

  % output column of values from 1 to $stop$
 
  if stop>=0
    y = zeros(1:stop-x) % what if x isn't zero?
  else
    disp(['evil x!'])
    break % actually, you should avoid $break$s at all cost...
          % For a taste of Java, think "System.exit(0)"
   end
   
  i = 1 % index for vector y
  while (x < stop) 
     x = x + 1; % increment x by 1
     y(i) = x
     i = i + 1;
    pause
  end

  x % what's x when loop ends?
  y

  % notes:
  % -----
  % boundary conditions -- I have loop possibly stopping for a count of
  %    zero. That's a kind of boundary condition, or limiting value
  %    Actually, the result isn't too pretty if you enter 0 for $stop$.
  %    MATLAB returns the empty matrix $[]$
  % 
  % vectorizing -- overall my style is OK here, but there's some efficiency
  %    problems. You don't really need a loop to gather a count of values!
  %    Vectorizing code means finding a way for MATLAB's array to
  %    supercede a loop. Using built-in arrays generally works faster than
  %    processing a loop. Not all languages have this feature, though.



%-------------------------------------------------------------------------------
% notes to self -- tic, toc, break
% need a $for$
