Keyboard input/Obtain a Y or N response: Difference between revisions
Keyboard input/Obtain a Y or N response (view source)
Revision as of 01:30, 12 July 2019
, 4 years ago→{{header|BASIC}}: The examples under the BASIC header are now in alphabetical order, hopefully making it easier for more people to find the specific example they're looking for.
(added MiniScript example) |
Childishbeat (talk | contribs) m (→{{header|BASIC}}: The examples under the BASIC header are now in alphabetical order, hopefully making it easier for more people to find the specific example they're looking for.) |
||
Line 102:
</lang>
==={{header|
<lang
REPEAT▼
120 DO ▼
==={{header|Commodore BASIC}}===▼
<lang basic>10 PRINT "PRESS Y OR N TO CONTINUE:";▼
20 POKE 198, 0: REM CLEAR KEY BUFFER▼
30 GET K$▼
40 IF K$ <> "Y" AND K$ <> "N" THEN 30▼
50 PRINT K$</lang>▼
Note that 198 is the location of the keyboard buffer index on the VIC-20, C-64, and C-128. On the PET, the correct location is 158, while on the Plus/4 and C-16, it's 239.▼
The loop on lines 30 - 40 will cycle as fast as the interpreter can go, assigning K$ the empty string until the user presses a key. On versions of BASIC later than the 2.0 on the VIC and 64 (e.g. 3.5 on the C-16 and Plus/4, 7.0 on the C-128), GETKEY may be used in place of GET. GETKEY will wait for the user to press a key before continuing, so the polling is done in the BASIC interpreter's machine language code, and the BASIC loop only cycles when the user presses a key other than Y or N.▼
==={{header|GWBASIC}}===
Line 122 ⟶ 132:
90 PRINT "The response was "; T$
</lang>
<lang IS-BASIC>100 GET K$ ! Flush the keyboard buffer
▲120 DO
130 LET K$=LCASE$(INKEY$)
==={{header|Locomotive Basic}}===
Line 142 ⟶ 160:
40 IF k$ <> "y" AND k$ <> "Y" AND k$ <> "n" AND k$ <> "N" THEN GO TO 30
50 PRINT "The response was "; k$</lang>
▲==={{header|BBC BASIC}}===
▲ PRINT "Press Y or N to continue"
▲ REPEAT
▲ UNTIL key$="Y" OR key$="N"
▲ PRINT "The response was " key$</lang>
▲==={{header|Commodore BASIC}}===
▲<lang basic>10 PRINT "PRESS Y OR N TO CONTINUE:";
▲20 POKE 198, 0: REM CLEAR KEY BUFFER
▲30 GET K$
▲40 IF K$ <> "Y" AND K$ <> "N" THEN 30
▲50 PRINT K$</lang>
▲Note that 198 is the location of the keyboard buffer index on the VIC-20, C-64, and C-128. On the PET, the correct location is 158, while on the Plus/4 and C-16, it's 239.
▲The loop on lines 30 - 40 will cycle as fast as the interpreter can go, assigning K$ the empty string until the user presses a key. On versions of BASIC later than the 2.0 on the VIC and 64 (e.g. 3.5 on the C-16 and Plus/4, 7.0 on the C-128), GETKEY may be used in place of GET. GETKEY will wait for the user to press a key before continuing, so the polling is done in the BASIC interpreter's machine language code, and the BASIC loop only cycles when the user presses a key other than Y or N.
=={{header|Batch File}}==
|