21 de jun. de 2018

Looping a range of number using mod "%"

If you want to loop through a range of number and starts from the beginning again, you can use Mod "%".

destPoint = 0;
destPoint = (destPoint + 1) % patrolTargets.Length;

if patrolTargets.Length = 5, for example, destPoint will be 0, 1, 2, 3, 4 and 0 again, if the expression is inside a loop statement.


Nenhum comentário: