The '%' sign

Can anyone explain what the ‘%’ symbol does in this pice of code:

b =l.points[(j % #l.points)+1]

It’s from a for loop and gets the current Key in pair + 1 - but how does it work?

It"s from the Physics Lab examble.

It’s the modulus function. n%m returns the remainder when n is divided by m. In that code, I guess the purpose is to get the next element of the array with “wrap around” so that if j = #l.points then j % #l.points returns 0 so the net result is 1, the first element in the array.

Further: Modulo is defined as:

a % b == a - math.floor(a/b)*b

See the Lua reference here.

Thanks - I now know I’m not a programmer, but just fooling around :slight_smile: