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,3323ee59cb66d2b6 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!news3.google.com!news.glorb.com!newspeer2.se.telia.net!se.telia.net!masternews.telia.net.!newsb.telia.net.POSTED!not-for-mail From: =?ISO-8859-1?Q?Bj=F6rn_Persson?= User-Agent: Mozilla Thunderbird 1.0.7-1.1.fc4 (X11/20050929) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: do while loop help ( newbie) References: <1139094979.043765.42770@g14g2000cwa.googlegroups.com> <1139114348.153402.214530@g14g2000cwa.googlegroups.com> In-Reply-To: <1139114348.153402.214530@g14g2000cwa.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Date: Sun, 05 Feb 2006 21:25:28 GMT NNTP-Posting-Host: 83.250.94.67 X-Complaints-To: abuse@telia.com X-Trace: newsb.telia.net 1139174728 83.250.94.67 (Sun, 05 Feb 2006 22:25:28 CET) NNTP-Posting-Date: Sun, 05 Feb 2006 22:25:28 CET Organization: Telia Internet Xref: g2news1.google.com comp.lang.ada:2785 Date: 2006-02-05T21:25:28+00:00 List-Id: isaac2004 wrote: > thanx for the help i understand about the exit when loop but is there a > way to do it that uses the for while loop instead because i can do it > with the exit when but i guess i didnt specify that earlier. thanx for > the code The fact that NewNumber was uninitialized the first time the loop condition was evaluated is a hint that "while" might not be the best solution. You always want to do the calculation at least once, so there's no need to have a condition on entering the loop. There are several ways to do it with "while" anyway. Here are a few: � Introduce an extra variable "Previous_Number". � Do the test in the best place and store the result in a boolean variable "Done". � Enclose part of the loop body in an "if" statement so that it's skipped the first time. � Duplicate part of the loop body outside the loop. This gets very ugly if more than one or two lines are duplicated. � Turn part of the loop body into a procedure and call it both inside and outside the loop. None of those are as clean as a loop-and-a-half with "exit when". What's wrong with "exit when"? -- Bj�rn Persson PGP key A88682FD omb jor ers @sv ge. r o.b n.p son eri nu