vendredi 22 février 2019

Iterating an array (modulo if logic)

Im trying to use a counter to iterate an array of objects when the user clicks a button;

The array contains 6 elements but will contain more or less in other scenarios, the array length is then multiplied by 2 / 3 / 4 etc depending on input..

Example:

arrlength=12 / 2 = 6,

arrlength=16 / 3 = 6,

arrlength=24 / 4 = 6,

arrlength=30 / 5 = 6,

What I want to have happen is that whenever the counter has counted to 6, 12, 18 (increments of 6, depending on original content before multiplication)... it will execute some code - but I dont want a huge if statement containing all these numbers, how can I solve this problem?

I have tried to experiment with the modulus operator but haven't had any luck yet.

Sorry if my question is unclear!

Aucun commentaire:

Enregistrer un commentaire