Lets say I have a sequence of 8 items, these loop such that after 8 comes 1.
1, 2, 3, 4, 5, 6, 7, 8
If the selected item is number 7 how do I get the number three places ahead, ie: 2 ?
I have:
var total; // (total number in sequence)
var pos; // (current position number)
if ( pos < total) {
threeIncrement = pos+3;
} else {
threeIncrement = ??????
}
Use
%, the modulus operator.