

Task

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.




to yorn
  type [Press Y or N to continue: ]
  local "clear
  make "clear readchars 0 ; clear input buffer
  local "yorn
  do.until [make "yorn readchar] [or equal? :yorn "Y equal? :yorn "N]
  print :yorn
  output :yorn
end