x=1
term=1;
total=term
imax=100000
for i=1:imax
    term=term*x/i;
    oldtotal=total;
    total=total+term;
    if total==oldtotal
        fprintf('Stopped summing after %i terms.\n',i)
        break
    end
end
expVal=total
expErr=abs(expVal-exp(1))
