The inner loop

During each iteration of the inner loop:

This function:

(This program does not attempt to service the middle button, a mouse wheel, etc.)