comp.lang.ada
 help / color / mirror / Atom feed
From: "Björn Persson" <spam-away@nowhere.nil>
Subject: Re: do while loop help ( newbie)
Date: Sun, 05 Feb 2006 21:25:28 GMT
Date: 2006-02-05T21:25:28+00:00	[thread overview]
Message-ID: <c3uFf.43920$d5.199938@newsb.telia.net> (raw)
In-Reply-To: <1139114348.153402.214530@g14g2000cwa.googlegroups.com>

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



  reply	other threads:[~2006-02-05 21:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-04 23:16 do while loop help ( newbie) isaac2004
2006-02-05  2:01 ` jimmaureenrogers
2006-02-05  8:03   ` Pascal Obry
2006-02-05 12:18   ` Stephen Leake
2006-02-05  2:07 ` Jeffrey R. Carter
     [not found] ` <bjfau11bp7g4b5id8vprbai6bc81qfgr96@4ax.com>
2006-02-05  4:39   ` isaac2004
2006-02-05 21:25     ` Björn Persson [this message]
2006-02-05 22:25       ` Jeffrey R. Carter
2006-02-06  1:01         ` Björn Persson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox