javascript - Trigger after every 3rd time -
this question has answer here:
i want trigger event after every 3rd time.
for (i = 0; < 5000; i++) { // when == 3, == 6, == 9 etc. if () { trigger(); } }
i can't figure out how represent in code, brain stuck.
unless write: if == 3
if == 6 etc.
but write millions of these since unlimited.
you could...
- increment
i
3, not 1 - use
modulo
check
so
for (i = 0; < 5000; i=i+3) { ... }
or
for (i = 0; < 5000; i++) { // when == 3, == 6, == 9 etc. if (i % 3 == 0) { trigger(); } }
Comments
Post a Comment