How to resolve the algorithm Keyboard input/Obtain a Y or N response step by step in the PureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Keyboard input/Obtain a Y or N response step by step in the PureBasic programming language
Table of Contents
Problem Statement
Obtain a valid Y or N response from the keyboard. The keyboard should be flushed, so that any outstanding key-presses are removed, preventing any existing Y or N key-press from being evaluated. The response should be obtained as soon as Y or N are pressed, and there should be no need to press an enter key.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Keyboard input/Obtain a Y or N response step by step in the PureBasic programming language
Source code in the purebasic programming language
PrintN("Press Y or N to continue")
Repeat
; Get the key being pressed, or a empty string.
Key$=UCase(Inkey())
;
; To Reduce the problems with an active loop
; a Delay(1) will release the CPU for the rest
; of this quanta if no key where pressed.
Delay(1)
Until Key$="Y" Or Key$="N"
PrintN("The response was "+Key$)
You may also check:How to resolve the algorithm Run-length encoding step by step in the 8086 Assembly programming language
You may also check:How to resolve the algorithm Function definition step by step in the Diego programming language
You may also check:How to resolve the algorithm Merge and aggregate datasets step by step in the Raku programming language
You may also check:How to resolve the algorithm Sum of squares step by step in the Slate programming language
You may also check:How to resolve the algorithm Determine if a string is numeric step by step in the Déjà Vu programming language