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