function sum = sumUpToK(v,k)
%sumUpToK  sums a vector from 1 up through k
%
% consumes:
%    v: a vector of numbers
%    k: an index in that vector
%
% produces 
%    sum: a scalar number 
%
%  examples:
%
%     >> sumUpToK([3 4 2 1],3)
%     ans = 9
%     >> sumUpToK([3 4 2 1],4)
%     ans = 10
%     >> sumUpToK([3 4 2 1],1)
%     ans = 3
%     >> sumUpToK([3 4 2 1],0)
%     ans = 0
%     >> sumUpToK([3 4 2 1],-1)
%     ans = 0  
%     >> sumUpToK([3 4 2 1],5)
%     ans = 0  
  
  sum = 0;
  if (k <= 0) || (k>length(v))
    return;
  end;
  
  for (ii = 1:k)
    sum = sum + v(ii);
  end;
  
  return;
  
end


