File : yorn.sp


$ spar yorn
Your answer? (Y/N) Y

#!/usr/local/bin/spar

pragma annotate( summary, "yorn" );
pragma annotate( description, "Obtain a valid Y or N response from the keyboard. The" );
pragma annotate( description, "keyboard should be flushed, so that any outstanding keypresses" );
pragma annotate( description, "are removed, preventing any existing Y or N keypress from" );
pragma annotate( description, "being evaluated. The response should be obtained as soon as" );
pragma annotate( description, "Y or N are pressed, and there should be no need to press an" );
pragma annotate( description, "enter key. " );
pragma annotate( see_also, "http://rosettacode.org/wiki/Keyboard_Input/Obtain_a_Y_or_N_response" );
pragma annotate( author, "Ken O. Burtch" );

pragma ada_95;
pragma restriction( no_external_commands );

procedure yorn is
  answer : character;
begin
  put( "Your answer? (Y/N) " );
  loop
    answer := inkey;
    case answer is
    when 'Y'|'y' =>
       answer := 'Y';
       exit;
    when 'N'|'n' =>
       answer := 'N';
       exit;
    when others =>
       null;
    end case;
  end loop;
  put_line( answer );
end yorn;

-- VIM editor formatting instructions
-- vim: ft=spar