Q:

Print something every 10 loop iterations

I need to print something in a loop everytime a number is 10, 20, 30, 40...
It should only print once and then continue the loop and print again when the number is divisible by 10.
How can I achieve this?

A:

for ($i = 0; $i < 100; $i++) {
    if ($i % 10 == 0) echo $i."\n";
    // do something
}

Generally the modulus operator (%) is what you need here. It calculates the remainder of a division. So: 7 % 5 = 2 and 18 % 5 = 3.

