Page 1 of 1

i am confused about using the or-operator

Posted: Thu Apr 03, 2008 4:21 pm
by Andi
Hi all!
I have a very special problem:

i try to receive two characters with my rs232 component.
First i try to check if the first incoming character is an 'a' or 'b' or 'c'.
If it is one of the following characters, i try to check the second character if it is an 'a' or 'b' ... or 'o'.

At the moment i check every single incoming character with a single if-command. Now i have the problem that i have
more than 45 if-commands in my source code.

When i am trying to use the || in my if-command and compare the incoming rs232 value with my test variable
(if test= 'a' || 'b' || 'c' )
...
...
it doesnt work.

What is my mistake?
plz help me!

Regards,andi

Re: i am confused about using the or-operator

Posted: Thu Apr 03, 2008 5:57 pm
by Sean
The || operator performs the locical OR operation. Anything that does not have the value 0 is treated as TRUE.

The expression 'a' || 'b' || 'c' will always be TRUE because all the parameters are TRUE.

The code to test each parameter individually would be:

if (test='a') || (test='b') || (test ='c') .... etc.

Here each individual comparison provides the TRUE/FALSE results that are ORed together.