You should be able to create a counter inside your outer loop.