help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Suggestion: add do-enddo(condition)


From: Ted Harding
Subject: Re: Suggestion: add do-enddo(condition)
Date: Thu, 27 Jan 2000 22:26:55 -0000 (GMT)

On 27-Jan-00 John W. Eaton wrote:
> 
> So, we are left with two cases, which you can currently implement
> with
> 
>   do ... while (condition)  -->
> 
>     while (1)
>       ...
>       if (! condition) break endif
>     endwhile
> 
>   do ... until (condition)  -->
> 
>     while (1)
>       ...
>       if (condition) break endif
>     endwhile
> 
> but the new forms might be a little clearer.
> 
> Implementing this would not be hard, if anyone is interested.

I would be in favour of introducing these forms,

(a) for convenience,

(b) because "built-in" implementation would normally be much faster
    than interpretation of the above implementations.

However, I suggest it might be better to do the test _before_ executing
the body -- i.e. if the loop is entered with its exit condition already
true, then the body would not be executed -- for both 'while'
and 'until' (since either way round 'until' == 'while not'). 

This would be consistent with the behaviour of the C 'while (cond) body'
construct, which does it this way (as opposed to the C construct
'do body while (cond)' which tests the condition after executing the
body). The difference is that with the post-test the body is executed
at least once; with the pre-test it might not be executed at all.

There are arguments for the merits of either way round, but I think
that the pre-test form is likely to be the one most often useful.

Best wishes,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Date: 27-Jan-00                                       Time: 22:26:55
------------------------------ XFMail ------------------------------



-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]