in reply to Which loop should I use?

Keep in mind that sometimes your output is not displayed right away because you didn't finish upwith a linefeed. Almost all print statements should finish with one, for example:
print "This is my comment\n";
The "\n" will send the line to the terminal immediately. If you don't have a trailing linefeed, the line might get buffered, which can delay its appearance.