From: Jerry <lanceboyle@qwest.net>
Subject: How to exit a loop with keyboard input
Date: Sun, 11 Apr 2010 21:12:38 -0700 (PDT)
Date: 2010-04-11T21:12:38-07:00 [thread overview]
Message-ID: <176f2831-ce2a-4bb1-9e04-47f662fc7176@q23g2000yqd.googlegroups.com> (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;
next reply other threads:[~2010-04-12 4:12 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-12 4:12 Jerry [this message]
2010-04-12 8:50 ` How to exit a loop with keyboard input 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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox