modulo of a negative number can give some surprising results. A negative index in that array would cause it to throw a range error, so my guess is that's what you're getting. If you do %array.length though it becomes an unsigned math and thus will never be negative, explaining the different result.

Remember btw that when foreaching over an array, the value you get is the number in the array, not the index.

Reply via email to