x=1
term=1;
oldtotal=Inf;
total=term;
imax=100000;
i=0;
while total ~= oldtotal
    i=i+1;
    term=term*x/i;
    oldtotal=total;
    total=total+term;
    if i >= imax
        fprintf('Too many terms: %i',imax)
        break
    end
end
expValue=total
expError=abs(exp(x)-expValue)