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

From Rosetta Code
Content added Content deleted
(→‎{{header|PureBasic}}: Added PureBasic)
Line 6: Line 6:
==={{header|ZX Spectrum BASIC}}===
==={{header|ZX Spectrum BASIC}}===


10 IF INKEY$<>"" THEN GOTO 10
10 PRINT "Press Y or N to continue"
20 PRINT "Press Y or N to continue"
20 IF INKEY$<>"" THEN GOTO 20
30 LET k$ = INKEY$
30 LET k$ = INKEY$
40 IF k$ = "y" OR k$ = "Y" OR k$ = "n" OR k$ = "N" THEN GOTO 60
40 IF k$ = "y" OR k$ = "Y" OR k$ = "n" OR k$ = "N" THEN GOTO 60
Line 14: Line 14:


[[Category:Keyboard Input]]
[[Category:Keyboard Input]]

=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang PureBasic>PrintN("Press Y or N to continue")
<lang PureBasic>PrintN("Press Y or N to continue")

Revision as of 18:03, 8 October 2010

Keyboard input/Obtain a Y or N response is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Obtain a valid Y or N response from the keyboard. The keyboard should be flushed, so that any outstanding keypresses are removed, preventing any exiting Y or N keypress from being evaluated

BASIC

ZX Spectrum BASIC

10 IF INKEY$<>"" THEN GOTO 10
20 PRINT "Press Y or N to continue"
30 LET k$ = INKEY$
40 IF k$ = "y" OR k$ = "Y" OR k$ = "n" OR k$ = "N" THEN GOTO 60
50 GOTO 30
60 PRINT "The response was "; k$

PureBasic

<lang PureBasic>PrintN("Press Y or N to continue") Repeat: Key$=UCase(Inkey()) Until Key$="Y" Or Key$="N" PrintN("The response was "+Key$)</lang>