From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,430e73ffe1dca4e9,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!q23g2000yqd.googlegroups.com!not-for-mail From: Jerry Newsgroups: comp.lang.ada Subject: How to exit a loop with keyboard input Date: Sun, 11 Apr 2010 21:12:38 -0700 (PDT) Organization: http://groups.google.com Message-ID: <176f2831-ce2a-4bb1-9e04-47f662fc7176@q23g2000yqd.googlegroups.com> NNTP-Posting-Host: 75.172.180.11 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1271045558 12162 127.0.0.1 (12 Apr 2010 04:12:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 12 Apr 2010 04:12:38 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: q23g2000yqd.googlegroups.com; posting-host=75.172.180.11; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/528.16+(KHTML, like Gecko, Safari/528.16) OmniWeb/v622.8.0,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:10929 Date: 2010-04-11T21:12:38-07:00 List-Id: [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;