Jump to content

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

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.
(added MiniScript example)
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|IS-BBC BASIC}}===
<lang IS-BASICbbcbasic>100 GET K$ ! Flush the keyboardREPEAT UNTIL INKEY$(0) = buffer""
110 PRINT "Press Y or N to continue."
REPEAT
120 DO
130 LET K key$ =LCASE$(INKEY GET$)
140 LOOP UNTIL Kkey$="yY" OR Kkey$="nN"
150 PRINT "The response was ";K 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|GWBASIC}}===
Line 122 ⟶ 132:
90 PRINT "The response was "; T$
</lang>
 
==={{header|BBC IS-BASIC}}===
<lang IS-BASIC>100 GET K$ ! Flush the keyboard buffer
110 PRINT "Press Y or N to continue."
120 DO
130 LET K$=LCASE$(INKEY$)
140 LOOP UNTIL keyK$="Yy" OR keyK$="Nn"
150 PRINT "The response was " key;K$</lang>
 
==={{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}}===
<lang bbcbasic> REPEAT UNTIL INKEY$(0) = ""
PRINT "Press Y or N to continue"
REPEAT
key$ = GET$
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}}==
441

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.