evaluation of 'or' statements in conditional

E. Joshua Rigler relgire at gmail.com
Mon May 19 15:19:31 CDT 2008


I have a non-functional 'do until' loop that, when simplified, looks like this:

   do
      do_stuff();
      i = increment_array_index(i);
   until i==0 || i==(max_i+1) || array(i) == some_value

The idea is to check if the bounds of the array have been exceeded,
then check to see if the array element meets a pre-defined condition
that breaks the loop.  I guess I expected the condition to return true
as soon as the first item returned true, but it looks like Octave
actually evaluates every single expression, which results in an
attempt to address the array with an out of bounds index.

My question is, is there a preferred way to do this that does not
involve placing a conditional break inside the loop when the array
bounds are exceeded?

-EJR


More information about the Help-octave mailing list