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,66144fcff23c0cc6 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.66.72.131 with SMTP id d3mr8792694pav.38.1357297165233; Fri, 04 Jan 2013 02:59:25 -0800 (PST) Path: 6ni80917pbd.1!nntp.google.com!news.glorb.com!feeder.erje.net!us.feeder.erje.net!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: Trouble with loop in Ada Date: Fri, 4 Jan 2013 10:59:24 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Injection-Date: Fri, 4 Jan 2013 10:59:24 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="dfff62e1e537b55df42008571c03e0fe"; logging-data="3306"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tvCQcJyClKEExjaSmK43VYH9ahwzIzqg=" User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Cancel-Lock: sha1:k2QEvuR9RXfnNDegTdZct6vHZsM= Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: 2013-01-04T10:59:24+00:00 List-Id: On Fri, 04 Jan 2013 04:32:28 +0000, Derek Wyss wrote: > Hello, > > I'm new to Ada and I'm trying to write a toy unix command shell just to > explore the programming language. So far I have a very small program, > but I am confused about its behavior. > Can anyone offer an explanation as to why I need to press enter? I > suspect it has to do with my use of End_Of_File and the way it "looks > ahead" but I'm not really sure. The confusing thing to me is not that you have to press enter, but that you have to press it twice the first time round. I started it and pressed ijklmn THEN return... ijklmn Enter a character> you entered: i Enter a character> you entered: j Enter a character> you entered: k ... which explains it. (1) First, End_Of_File must block until there is input. (It has to wait to see if you are going to type Ctrl-C) And there isn't input until there is at least one character followed by a return. (2) Then Get returns one character at a time from the line buffer, until it runs out, when it blocks again until there is more input. So the behaviour comes from the library functions behind Get and End_Of_File rather than the loop. The question is whether you can get what you want from these, or need to find alternatives. Now the good news : loops are more flexible in Ada; there are other ways of using them. So your immediate problem can be solved by: loop Put("Enter a character> "); Get(input_char); Put("you entered: " & input_char); New_line; exit when End_Of_File; end loop; Oh and very nicely done on the toy example - that's the way to get help! - Brian