  n = 17                        % <-- print n at the beginning
  step = 0;                     % <-- counter starts at 0
  while ( n ~= 1 )
    if ( mod ( n, 2 ) == 0 )    % <-- if n is even, do this
      n = n / 2;
    else                        % <-- otherwise, do this
      n = 3 * n + 1;
    end
    step = step + 1;            % <-- counter goes up by one
  end
  step                          % <-- print steps at end
