I’ll use JavaScript syntax and provide a JS fiddle POC, but this really applies to almost any language – at least any that use indexed arrays (all that I can think of).

To get an index greater than length to “wrap” back from the beginning, use a simple modulus:

if ( index >= length ) {
    index = index % length;

To get a negative index to wrap from the end, it’s similar:

if( index < 0 ) {
    index = length + ( index % length );

Both maintain the “step”, so if you use index = 987687, or in a loop index -= 3, it’ll keep the appropriate position.

POC: http://jsfiddle.net/moagrius/v64xN/