Can you say this?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2010
    Posts
    88

    Default Can you say this?

    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

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Can you say this?

    I would think it should be IF X=1 OR X=2 THEN....

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Can you say this?

    Quote Originally Posted by ERMEGM View Post
    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

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Can you say this?

    Quote Originally Posted by Ioannis View Post
    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.

    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Can you say this?

    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

  6. #6
    Join Date
    Jan 2010
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: Can you say this?

    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

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts