[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
evaluation of 'or' statements in conditional
From: |
John W. Eaton |
Subject: |
evaluation of 'or' statements in conditional |
Date: |
Mon, 19 May 2008 16:57:01 -0400 |
On 19-May-2008, E. Joshua Rigler wrote:
| 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?
The || and && should short circuit. If not, then it is a bug, but I'm
unable to reproduce this problem with the example I made up:
x = [1,2,3,4,5]; i = 2; do i, --i; until (i == 0 || x(i) == 10);
If you think you've found a bug in Octave, then please submit a
*complete* bug report to the address@hidden list.
jwe