% hail_next.m
%  Take one step of the Collatz sequence and print the result.
%  The variables I and N must already be defined!
%  I should be set to 0.
%
while ( true )

  fprintf ( ' %d: N = %d\n', i, n );
  pause

  if ( n == 1 )
    fprintf ( '  Terminate.\n' );
    i = 0;
    break;
  end

  i = i + 1;
  if ( mod ( n, 2 ) == 0 )
    n = n / 2;
  else
    n = 3 * n + 1;
  end

end



