function ubvec = ubvec_next ( n, ubvec )

%*****************************************************************************80
%
%% UBVEC_NEXT generates the next UBVEC.
%
%  Discussion:
%
%    The vectors are produced in the order:
%
%    (0,0,...,0),
%    (0,0,...,1),
%    ...
%    (1,1,...,1)
%
%    and the "next" vector after (1,1,...,1) is (0,0,...,0).  That is,
%    we allow wrap around.
%
%    A UBVEC is a vector of N binary digits.
%
%    A UBVEC can be interpreted as a binary representation of an
%    unsigned integer, with the first entry being the coefficient of
%    2^(N-1) and the last entry the coefficient of 1.
%
%    UBVEC   #
%    -----  --
%    00000   0
%    00001   1
%    00010   2
%    10000  16
%
%  Example:
%
%    N = 3
%
%    Input      Output
%    -----      ------
%    0 0 0  =>  0 0 1
%    0 0 1  =>  0 1 0
%    0 1 0  =>  0 1 1
%    0 1 1  =>  1 0 0
%    1 0 0  =>  1 0 1
%    1 0 1  =>  1 1 0
%    1 1 0  =>  1 1 1
%    1 1 1  =>  0 0 0
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    19 November 2015
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the dimension of the vectors.
%
%    Input/output, integer UBVEC(N), on output, the successor to the
%    input vector.
%
  for i = n : -1 : 1

    if ( ubvec(i) == 0 )
      ubvec(i) = 1;
      return
    end

    ubvec(i) = 0;

  end

  return
end
