PDA

View Full Version : Can you say this?



ERMEGM
- 20th March 2011, 07:49
Was wondering if PBP will allow this?

if x = 1 OR 2 then do this

It compiled fine, but wasn't sure if you could have an OR statement on the condition side.

Tony

HenrikOlsson
- 20th March 2011, 08:08
I would think it should be IF X=1 OR X=2 THEN....

Ioannis
- 20th March 2011, 10:49
Was wondering if PBP will allow this?

if x = 1 OR 2 then do this

It compiled fine, but wasn't sure if you could have an OR statement on the condition side.

Tony

It sure compiled fine because regarding the syntax it is correct. It checks if x equals 1 and if true then it OR's it with 2.

Of course the result is not what you expect, but Henrik gave you the answer.

Ioannis

sayzer
- 20th March 2011, 18:29
It sure compiled fine because regarding the syntax it is correct. It checks if x equals 1 and if true then it OR's it with 2.

Of course the result is not what you expect, but Henrik gave you the answer.

Ioannis

IF x and y = 3 then z = 4
IF x or y = 3 THEN z = 4
IF x OR y and z = 4 then z = 5


These all compile fine. Sometimes I miss the logic and since these do not throw any error, I loose time finding the mistake.

:)

BrianT
- 20th March 2011, 22:37
The PBP help file for the AND statement says.....
Be sure to use parenthesis to tell PICBasic the exact order you want the operations to be performed.....

That means your original statement should look like.....
IF (X=1) OR (X=2) THEN....

HTH
BrianT

ERMEGM
- 21st March 2011, 03:30
Thanks guys for the help. Sometimes, the answer is right in front of you, but you're so stuck on seeing it the other way, that your mind doesn't realize it. The way I wrote it sounded so logical, but I know the chip isn't that smart, hence, why we have to tell it EXACTLY what to do or else it won't do it.

Before I could get an answer, I rewrote it into separate IF statements. Seems to flow that way too. Thanks again.

Tony