function n = countM( x )
% COUNTM Count how many times x can be updated to x^2 - 1 before exceeding 1,000,000.

% This function uses a standard while loop counting idiom, i.e., loop as
% long as the desired condition (x > 1,000,000 in this case) isn't true,
% incrementing a counter each time.

n = 0;                  % The counter

while x <= 1000000      % Update x and count until x exceeds 1,000,000
    x = x^2 - 1;
    n = n + 1;
end

end