How to resolve the algorithm Keyboard input/Obtain a Y or N response step by step in the Oforth 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 Oforth 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 Oforth programming language
Source code in the oforth programming language
import: console
: YorN
| c |
System.Console flush
doWhile: [
System.Console receiveChar toUpper ->c
c 'Y' <> c 'N' <> and
]
c ;
You may also check:How to resolve the algorithm Playing cards step by step in the Elixir programming language
You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the Wart programming language
You may also check:How to resolve the algorithm Y combinator step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the Forth programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the Icon and Unicon programming language