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: John W. Eaton
Subject: Re: Suggestion: add do-enddo(condition)
Date: Thu, 27 Jan 2000 15:08:03 -0600 (CST)

People have proposed

  1.      do ... enddo (condition)
  2.      do ... while (condition)
  3.      do ... until (condition)
  4.  repeat ... until (condition)

For completenes, I'll add

  5.  repeat ... while (condition)

Although it is consistent with the typical `foo ... endfoo' syntax of
Octave, I don't like 1 much because it is not clear to me whether the
loop runs while the condition is true or until it is true.  Both 3 and
4 are the same, as are 2 and 5, except for the keyword repeat vs. do.
I don't have a strong preference.

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.

Using while as a keyword to end loops as well as begin them does not
present a serious problem for the parser.

Note that since repeat or do and until would become keywords, they
would no longer be available as possible variable names, so that could
be a compatibility problem.

Implementing this would not be hard, if anyone is interested.

jwe



-----------------------------------------------------------------------
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]