comp.lang.ada
 help / color / mirror / Atom feed
* How to exit a loop with keyboard input
@ 2010-04-12  4:12 Jerry
  2010-04-12  8:50 ` Georg Bauhaus
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Jerry @ 2010-04-12  4:12 UTC (permalink / raw)


[Sorry for the cross-post.]

I have a loop which is doing a repetitive calculation. Sometimes the
loop runs a long time and I want to manually cause the loop to be
exited but have the program continue running, for example to save some
results to a file or do other calculations. Preferably I would just
hit a key or key combination.

I thought Get_Immediate would work (reading Cohen's book) but it does
not do what I want. For example, the following program stops looping
and requires me to hit RETURN even if I hit another key first. It
continues looping (very slowly) if I hold down the RETURN key.

I don't mind using GNAT-specific stuff as long as it gets the job
done.

Thanks.

Jerry


with Ada.Text_IO;
use  Ada.Text_IO;
procedure key is
    i         : Integer;
    Keystroke : Character;
    Available : Boolean;
begin
    i := 0;
    loop
        Put(Integer'Image(i));
        Get_Immediate(Keystroke, Available);
            if Available then
                if Keystroke = 'q' then
                    exit;
                end if;
            end if;
        i := i + 1;
    end loop;
    Put_Line("Finished");
end key;



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

end of thread, other threads:[~2010-04-16 14:03 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-12  4:12 How to exit a loop with keyboard input Jerry
2010-04-12  8:50 ` Georg Bauhaus
2010-04-12  9:21   ` Manuel Collado
2010-04-12 10:36 ` Jerry
2010-04-12 13:59   ` John McCormick
2010-04-13 19:38     ` Jerry
2010-04-12 15:14   ` Tero Koskinen
2010-04-12 16:16     ` John B. Matthews
2010-04-12 20:04     ` Simon Wright
2010-04-13 19:51       ` Jerry
2010-04-13 21:22         ` Simon Wright
2010-04-15  3:39           ` Jerry
2010-04-15  4:08             ` John B. Matthews
2010-04-15 18:51               ` Jerry
2010-04-16  0:44                 ` John B. Matthews
2010-04-16  4:43                   ` Simon Wright
2010-04-16 14:03                     ` John B. Matthews
2010-04-15 19:22             ` Simon Wright
2010-04-16 10:25               ` Jerry
2010-04-12 20:57 ` Alex Mentis
2010-04-12 22:51   ` Jerry
2010-04-16  0:06     ` BrianG
2010-04-16  7:23       ` Jerry

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