Loops the value, so that it is never larger than length and never smaller than 0.
The looped value.
The length of the loop.