comp.lang.ada
 help / color / mirror / Atom feed
* Did I understand it or not
@ 2014-01-08 20:27 Anh Vo
  2014-01-08 20:47 ` Pascal Obry
  2014-01-08 20:50 ` adambeneschan
  0 siblings, 2 replies; 5+ messages in thread
From: Anh Vo @ 2014-01-08 20:27 UTC (permalink / raw)


with Ada.Text_Io; use Ada;

procedure The_Unexpected is
   package Char_Io is new Ada.Text_Io.Enumeration_Io (Character);
   Health_Choice : Character := 'T';
   use Text_Io;
begin
   Health_Selection: loop
      begin
         Put ("Select Health Status '0', '1' or '2' => ");
         Char_Io.Get (Health_Choice);
         Put_Line (" < character '" & Health_Choice & "' is selected");
         if Health_Choice = '0' or else
            Health_Choice = '1' or else
            Health_Choice = '2' then
              exit;
         else
           Put ("Illegal selection! Choose another character > ");
         end if;
      exception
         when Data_Error =>
            Put_Line ("Use single quote like '0' or '1'");
            Flush;
      end;
   end loop Health_Selection;
end The_Unexpected;
---------------------------------------
GNAT was used on Linux and PC

I thought this piece of code should behave correctly regardless good or bad input from the operator. If a bad data is input, it is rejected and ask for another data input. However, it went to an infinite loop when a bad input is entered. For example, the program is in infinite loop if the operator type 1 instead of '1' when prompted.

I strongly believe that Flush subprogram did not clear the previous input from the terminal. Thus, Char_Io.Get completes without waiting for the input from the operator.

Once it is confirmed, I will compile a bug report. Thank you in advance for your help.

Anh Vo 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-01-08 23:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-08 20:27 Did I understand it or not Anh Vo
2014-01-08 20:47 ` Pascal Obry
2014-01-08 20:50 ` adambeneschan
2014-01-08 21:02   ` Anh Vo
2014-01-08 23:36     ` robin.vowels

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox