We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › OR operator between expressions in relations
Page Index Toggle Pages: 1
OR operator between expressions in relations? (Read 479 times)
OR operator between expressions in relations?
Apr 14th, 2007, 7:56am
 
Hello, I'm new to Processing and I'm wondering of there is some form of syntax that would help me speed up this code of mine, even if ever so slightly.
I have an if conditional that accesses a function that returns a value, comparing it to two other values, like this:
Code:
if(function(value) == variable1 || function(value) == variable2) { ... } 


I don't want to access the function twice, so would it be better to do this:
Code:
funcVar = function(value);
if(funcVar == variable1 || funcVar == variable2) { ... }

or is there a logical OR operator that can do OR's between to expressions in relations, like this?
Code:
if(function(value) == (variable1 || variable2)) { ... } 

Re: OR operator between expressions in relations?
Reply #1 - Apr 14th, 2007, 8:09am
 
that depends on what type your variables are.

(variable1 || variable2)
can only be done with boolean type variables. if one or both are true it returns true otherwise false.

i'd say use the middle version since it's the cleanes to read and i doubt there will be much difference to the last one.

F
Re: OR operator between expressions in relations?
Reply #2 - Apr 14th, 2007, 8:12am
 
It's an integer variable, so I can't do the third, I guess. Thank you very much for your timely response and helpful answer.
Page Index Toggle Pages: 1