Evaluating 'or' statements: bug or feature?

Bill Denney bill at denney.ws
Tue Jul 8 19:20:08 CDT 2008


Andy Sinton wrote:
> I've encountered this issue twice when running .m files in Octave
> (3.01, windows).
> With an 'or' statement such as
>
> if u > v | someFunction(b)
>
> chokes if there is no variable 'b', even though it is true that u > v.
>  I guess Matlab stops evaluating 'or' statements when it hits the
> first true statement and Octave keeps going?
> Is there a reason for this bug/feature?
> Thanks!

Hi Andy,

This is a topic that comes up relatively often.  The short answer is 
that if you want a shortcutting or, you need to use the double pipe 
(||).  The single pipe is an element-wise or while double is a boolean 
or.  Assuming that u, v, and the output of someFunction(b) are all 
scalars, you are probably wanting

u > v || someFunction(b)

Have a good day,

Bill


More information about the Help-octave mailing list