ade@pucc-i (D. Kakarigi) (08/01/85)
How would you expect the following loop to work? { Applicable to V 2 and 3/MS-DOS. } repeat { This may seem like useless code but } ... { it is conceiveably needed and it causes} writeln(....); { a very uncomfortable feature (?) of } ... { Turbo Pascal to surface to my surprise.} until keypressed { BTW, this problem was pointed to me by } { my colleague at work. Thanks Bill. } It should do the ... writeln ... until you press any key (with the exception of ^S if the C compiler flag is on, and ^C), right?. Well, it doesn't. The code for writing to stdout itself checks for keypressed using interrupt 16 and 1 in AL, appropriatelly. Then, if in fact a key was pressed, it goes and grabs the character with, again, interrupt 16 and 0 in AL, inappropriately. What happens is that the input buffer pointers get updated, (if AL=0) and the fact that a key was pressed during the write operation, is not the fact any more when your until keypressed line wants to examine it. That is OK if the key(s) pressed was ^S, but if it is something else, the loop is almost an infinite loop unless you happen to press a key while your program is executing somewhere between the writeln and the until keypressed. Instead, when the write code detects the keypressed (with AL=1), it should take the character which is automatically returned anyway (with the same INT 16 and AL=1), examine it, and only if the character was ^S should the code go and actually get it with INT 16 and AL=0 (in order to update pointers), otherwise do nothing. P.S. Another thing is that the write code checks for ^S after outputing the character instead of before. Matter of taste?