val a = -7 val b = 3
Manually fixing a negative remainder:
// Verification of remainder property: // a = (a/b)*b + r // -5 = (-5/3)*3 + (-2) -> -5 = (-1)*3 + (-2) = -5 ✓
In this case, 3 goes into 10 three times (making 9), leaving a remainder of 1.
When iterating over an array or list and you want to loop back to the beginning once you reach the end, modulo is the standard tool.
val a = -7 val b = 3
Manually fixing a negative remainder:
// Verification of remainder property: // a = (a/b)*b + r // -5 = (-5/3)*3 + (-2) -> -5 = (-1)*3 + (-2) = -5 ✓
In this case, 3 goes into 10 three times (making 9), leaving a remainder of 1.
When iterating over an array or list and you want to loop back to the beginning once you reach the end, modulo is the standard tool.