in reply to printing outside a for loop

Have you considered having two loops - one that gathers the statistics, and another that prints them out?

Cheers

mildside