comp.lang.ada
 help / color / mirror / Atom feed
From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Did I understand it or not
Date: Wed, 8 Jan 2014 12:27:54 -0800 (PST)
Date: 2014-01-08T12:27:54-08:00	[thread overview]
Message-ID: <66e43abe-7918-4296-a12f-a8454ea4cd80@googlegroups.com> (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 

             reply	other threads:[~2014-01-08 20:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-08 20:27 Anh Vo [this message]
2014-01-08 20:47 ` Did I understand it or not Pascal Obry
2014-01-08 20:50 ` adambeneschan
2014-01-08 21:02   ` Anh Vo
2014-01-08 23:36     ` robin.vowels
replies disabled

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