help-octave
[Top][All Lists]
Advanced

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

Re: Evaluating 'or' statements: bug or feature?


From: David Bateman
Subject: Re: Evaluating 'or' statements: bug or feature?
Date: Wed, 09 Jul 2008 11:15:20 +0200
User-agent: Thunderbird 2.0.0.12 (X11/20080306)

Bill Denney wrote:
> 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,
>
>   
Also read

http://www.gnu.org/software/octave/FAQ.html#MATLAB-compatibility

and in particular the section on short-circuit operators, for the
explanation why matlab's behavior in this case is a really bad idea, and
why they finally changed their might and also accepted "||" as the
short-circuit operator.

D.

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

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