You could certainly benefit from a second loop rather than hardcoding the indices. Use n as the loop condition to control the count.