Keyboard input/Obtain a Y or N response: Difference between revisions

Line 456:
 
=={{header|Fortran}}==
Standard Fortran has no special I/O statements that allow asynchronous actions (such as the KeyPressed and ReadKey functions of Turbo Pascal), so input is awaited in the usual fashion and a prompt should be supplied to indicate to the reader that a response is awaited, otherwise the user will confront a blank screen with nothing happening and will have to guess what might be expected. Further, there is no scheme for knowing if impending input has been waiting in an input buffer since before the need for a question arose, so it is not possible to flush such lines before requesting the special input. Impatience at the screenface can prompt typing ahead so that the next command will be immediately available but incorrectly anticipated input will likely wreck the run, though for yes/no responses you may be rescued if such input does not conform to the required form: the bad input will be ignored and the question asked afresh. Thus, the details of the specification cannot be met via standard Fortran, though a given system may have special subroutines equivalent to KeyPressed, etc. available.
 
Even so, asking questions can often be useful when messing about with tests, etc., so some routines for this can help. These were devised afresh at the Culham Science Centre, so there was some language generality:
<lang Fortran>
CHARACTER*120 FUNCTION REPLY(QUERY) !Obtain a text in reply.
1,220

edits