|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
print in a loopConsider the following codes:
Expected behaviour: the program prints a dot, then 0.5 seconds later it prints another dot, etc. Reality: the program seemingly doesn't do anything for a few seconds and then it prints all the dots together. Explanation: the output is buffered during the loop. After the loop, reaching the end of the program, the content of the buffer is printed on the screen in one go. SolutionIf you want to see the dots appear one after the other slowly, with some pause between them, you need to disable the buffering. You must flush the buffer explicitly, and then the content of the buffer (just one dot) will appear on the screen immediately:
𝥶Now a dot in printed, the program waits 0.5 seconds, another dot is printed, etc. |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |
||||||||