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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,88e2699149e680f4 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-06 09:13:45 PST Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn14feed!worldnet.att.net!207.217.77.102!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3DF0DAC4.1050102@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: File IO problem References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 06 Dec 2002 17:13:45 GMT NNTP-Posting-Host: 63.184.0.215 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 1039194825 63.184.0.215 (Fri, 06 Dec 2002 09:13:45 PST) NNTP-Posting-Date: Fri, 06 Dec 2002 09:13:45 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:31504 Date: 2002-12-06T17:13:45+00:00 List-Id: prashna wrote: > Hi all, > Pls have a look at the following code > > with text_Io; > use text_io; > Procedure FILE_IO_DEMO is > FILE_I, FILE_O : FILE_TYPE; > S : STRING(1..80); > Len : Integer; > begin > open (FILE_I, IN_FILE,"junk.txt"); > create(FILE_O, OUT_FILE, "output.txt"); > while END_OF_FILE(FILE_I) loop > GET_LINE(FILE_I, S, Len); > PUT_LINE(S(1..LEN)); > PUT_LINE(FILE_O,S(1..Len)); > end loop; > end; > > The contents of the file junk.txt is > lafeosbv > qfowep p4gowb > hfwevwpbv > > The program is creating output.txt but it contents are nil. This is an example of why, in 1980, Ichbiah, Barnes, & Firth recommended not using while loops. It is natural to think about the exit condition for a loop, but a while loop requires its opposite, the continuation condition. Had this been written with an exit: loop exit when End_Of_File (File_I); there would not have been a problem. -- Jeff Carter "From this day on, the official language of San Marcos will be Swedish." Bananas