You use the mod function on the loop counter.

THe remainder will be zero every 5 iterations...

for (mainLoop=0; mainLoop < N; mainLoop++)

{

....

if ((mainLoop % 5)==0)

{

//* PUT YOUR CODE IN HERE THAT EXECUTES EVERY 5th ITERATION *//

} //every 5th iteration

} //mainLoop

===============================================

the following table illustrates this pattern more clearly.

main loop counter remainder after dividing by 5

0 0

1 1

2 2

3 3

4 4

5 0

6 1

7 2

8 3

9 4

10 0

11 1

etc