javascript - How to do something on each third for loop iteration -
this question has answer here:
how can alert on each third loop iteration alert ("some text") on each third iteration, how can make it?
for(var = 1; < 20; i++) { alert("some text"); }
use modulo operator (%
):
for(var = 1; < 20; i++) { if (i % 3 === 1) { alert("some text"); } }
Comments
Post a Comment