Keyboard input/Obtain a Y or N response: Difference between revisions
Content added Content deleted
m (added whitespace before the TOC (table of contents), hyphenated key-press.) |
m (→{{header|REXX}}: changed/added comments and whitespace, changed indentations.) |
||
Line 984: | Line 984: | ||
<br>Some older Classic REXX interpreters have a keyboard read subroutine (BIF) so that the program can read keyboard keys as |
<br>Some older Classic REXX interpreters have a keyboard read subroutine (BIF) so that the program can read keyboard keys as |
||
<br>they are pressed (see the other versions below). |
<br>they are pressed (see the other versions below). |
||
<lang rexx>/*REXX program tests for a Y or N key when entered after a prompt.*/ |
<lang rexx>/*REXX program tests for a Y or N key when entered from keyboard after a prompt.*/ |
||
do queued(); pull; end /*flush stack if anything |
do queued(); pull; end /*flush the stack if anything is queued*/ |
||
prompt = 'Please enter Y or N for verification:' |
prompt = 'Please enter Y or N for verification:' /*this is the PROMPT message.*/ |
||
do until pos(ans,'NY')\==0 |
do until pos(ans,'NY')\==0 & length(ans)==1 /*keep looking for a Y or N answer.*/ |
||
say; say prompt /* |
say; say prompt /*display blank line; display prompt. */ |
||
pull ans /*get the answer(s) |
pull ans /*get the answer(s) and uppercase it.*/ |
||
ans |
ans=space(ans, 0) /*elide all blanks. */ |
||
end /*until*/ |
end /*until*/ |
||
/*stick a fork in it, we're done.*/</lang> |
/*stick a fork in it, we're all done. */</lang> |
||
===version 1 for PC/REXX and Personal REXX=== |
===version 1 for PC/REXX and Personal REXX=== |
||
This version of a REXX program works with PC/REXX and Personal REXX. |
This version of a REXX program works with PC/REXX and Personal REXX. |
||
<lang rexx>/*REXX program |
<lang rexx>/*REXX program tests for a Y or N key when entered from keyboard after a prompt.*/ |
||
prompt = 'Please |
prompt = 'Please enter Y or N for verification:' /*this is the PROMPT message.*/ |
||
do until pos(ans,'NYny')\==0 /*keep prompting until answer |
do until pos(ans, 'NYny') \== 0 /*keep prompting until answer= Y N y n */ |
||
say; say prompt /* |
say; say prompt /*display blank line; display prompt. */ |
||
ans= |
ans=inKey('wait') /*get the answer(s) from the terminal. */ |
||
end /*until*/ |
end /*until*/ |
||
/*stick a fork in it, we're all done. |
/*stick a fork in it, we're all done. */</lang> |
||
===version 2 for PC/REXX and Personal REXX=== |
===version 2 for PC/REXX and Personal REXX=== |
||
This version is the same as above, but has a more idiomatic technique for testing the response. |
This version is the same as above, but has a more idiomatic technique for testing the response. |
||
<lang rexx>/*REXX program |
<lang rexx>/*REXX program tests for a Y or N key when entered from keyboard after a prompt.*/ |
||
prompt = 'Please |
prompt = 'Please enter Y or N for verification:' /*this is the PROMPT message.*/ |
||
do until pos(ans,'NY')\==0 /*keep prompting |
do until pos(ans, 'NY')\==0 /*keep prompting 'til user answers Y│N */ |
||
say; say prompt /* |
say; say prompt /*display blank line; display prompt. */ |
||
ans= |
ans=inKey('wait'); upper ans /*get the answer(s); and uppercase it.*/ |
||
end /*until*/ |
end /*until*/ |
||
/*stick a fork in it, we're all done. |
/*stick a fork in it, we're all done. */</lang> |
||
=={{header|Ring}}== |
=={{header|Ring}}== |