PDA

View Full Version : What is "or" command?



Ignasius
07-13-2008, 02:13 PM
Helloooo,

I was hoping someone could please tell me what the "or" command is. Example:

if ((emitterId == 0) or (emitterId == 1)).....ect.

Thanks :)

chrisg
07-13-2008, 06:04 PM
Hi Ignasius,

Or means that if ANY of the statements are true, then the code will execute.

So, if it turned out that emitterId == 0 was not true, but emitterId == 1 was true, the code inside the if statement would run.

For example, we have a red apple, a banana and a red stone.


if (object.type == fruit or object.color == red)
{
// this will execute for all three objects,
//since they are all either fruits, or red.
}


if (object.type == fruit and object.color == red)
{
// this will execute only for the apple,
// since it has to be both a fruit and red.
}

So, your statement will execute if any of those sub-statements are true.

johnny
07-13-2008, 06:33 PM
Just to add I thnk the actual syntax for or is "||" :)

Ignasius
07-13-2008, 06:49 PM
Thank you chrisq and johnny. Yes the syntax was specifically what I was looking for || thanks johnny. And thanks chrisq for taking time to explain.:)

laxman
07-13-2008, 10:35 PM
also and is "&&"

Ignasius
07-14-2008, 01:01 AM
Thanks Laxman, Im making a list of all the operations I know now.
&&
++
+=
==
||
and all the obvious ones I learned in Algebra101 :)
thanks

Farla
07-14-2008, 03:46 AM
I'm not sure if this applies but theres a difference between logical && and binary & :). This applies to || and | :D.

In programming at least they are different i'm guessing since these are derived from programming they would be apply.

| - bitwise OR
& - bitwise AND

johnny
07-14-2008, 01:56 PM
Hey Farla, What you put there is interesting in the case of how it applies to expression writing, and MEL scripting. Although I have programmed before (a little), I got a little lost with how it could be applied. I always remember typing a "&&" and "||" is conditional statements, etc.

Would you mind giving an example or two like Chris did so I can make more sense of it?

Thanks :)

Farla
07-14-2008, 10:56 PM
Johnny i'm not sure if it does apply but my guesses is this is just a syntax thing.

Well anyways in programming

the & or | are used for binary digits/numbers called bitwise

eg. 00000001
10000111

you can do an | and & but this is into the computer science sector not grahpics :D.

Its more towards CPU/Architecture.

The && or || is used to evaluate a boolean expression such as

if ( DT great || DT excellent)
do something
else
do something else.

Ignasius
07-14-2008, 11:21 PM
I think you guys are speaking two different languages...hehe...:( Lame joke.

johnny
07-15-2008, 05:13 PM
Thanks Farla :)