Re: repeat vs. while [message #82154] |
Wed, 21 November 2012 14:37 |
Mark Piper
Messages: 198 Registered: December 2009
|
Senior Member |
|
|
On Wednesday, November 21, 2012 2:16:05 PM UTC-7, David Fanning wrote:
> rr...@stsci.edu writes:
>
>
>
>> Can anyone explain the difference between repeat and while? Is there any reason to use one vs. the other?
>
>
>
> REPEAT will check the loop condition at the bottom of the loop.
>
> WHILE will check the loop condition at the top of the loop.
>
>
>
> You use one or the other depending on when you want to
>
> stop executing the loop.
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Another way of thinking of this is that REPEAT is guaranteed to execute at least once, whereas WHILE may execute zero times.
mp
|
|
|
Re: repeat vs. while [message #82155 is a reply to message #82154] |
Wed, 21 November 2012 13:16  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
rryan@stsci.edu writes:
> Can anyone explain the difference between repeat and while? Is there any reason to use one vs. the other?
REPEAT will check the loop condition at the bottom of the loop.
WHILE will check the loop condition at the top of the loop.
You use one or the other depending on when you want to
stop executing the loop.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|