Update odometer

update_odometer is a function that implements an "odometer": that is, it increases the right-most entry of a vector by 1. If that right-most entry is now larger than its maximum allowed value then it "rolls over" to 0 and the second-to-right-most entry increases by 1. Similarly, if this entry is now too larger, it rolls over, and so on.

This function is useful if you are in a situation where you want to nest multiple for loops, but you don't know beforehand exactly how many of them there will be (since it depends on user input, for example).

Syntax

 * NEW_IND = update_odometer(OLD_IND,UPPER_LIM)

Argument descriptions

 * OLD_IND: The vector to be updated.
 * UPPER_LIM: A vector of the same length as OLD_IND with the property that its j-th entry specifies the "roll over" value of the j-th entry of OLD_IND</tt>. That is, the j</tt>-th value of OLD_IND</tt> is constrained to being in the interval from 0</tt> to UPPER_LIM(j)-1</tt> (inclusive).

Examples
The following code loops over all vectors of length 2 with the property that their first entry is 0, 1, or 2, and their second entry is 0 or 1: