Jump to content

compound boolean expressions examples?


frew
 Share

Recommended Posts

Hello,

Does anybody know of a good reference (ie with various examples) for creating compound boolean expressions?

Sometimes I want to create complex If statements with lots of AND, OR, and NOT, and XOR...but I wish I had some examples of what works in AutoIt.

For example, I think putting parentheses around various groupings is a good way to not have to be so concerned about

precedence causing problems.

I'm new to a lot of this. I checked the help and the forum, but I want more detailed examples of how to compose compound boolean expressions for situations where there's a complex condition that I want to express.

For example, I may want to express:

If $x = 20 Or $x > 50 And $y > 30 And $y < 100 And $y is Not 60 etc

I guess I could use comparison operators, but I'm trying to explore the advantages of using boolean operators too.

I'm just trying to understand how to be sure my compound boolean expressions will work. It would be helpful to see examples of a bunch of diverse compound boolean expressions.

If a little script test does not do as I expect, I don't want it to be be because I am doing the wrong syntax.

For example, I did this:

$i = 10
If Not $i = 11 Then MsgBox(0, '', $i)

and no message box shows up.

But when I did this

$i = 10
If Not ($i = 11) then MsgBox(0, '', $i)

the message box shows up because I put the $i = 11 inside parentheses.

Thanks for any ideas and examples, or other resources for me to check.

frew

Link to comment
Share on other sites

There are plenty of topics discussing this, just search the forum for Operator Precedence.

But really, the help file has everything you need.

The problem you're running into is that Not has higher precedence than all other operators, so Not $i = 11 is effectively evaluated as (Not $i) = 11.

For a comparison such as this, you should use <> instead.

If $i <> 11 then MsgBox(0, '', $i)

Feel free to use parenthesis until you get a better grasp of precedence.

Even when you have it down cold, they can still help with legibility.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Link to comment
Share on other sites

Thank you Skruge.

That actually is just what I needed, a point in the right direction.

Thanks for the links. (How could I miss that in the help file? I searched boolean and somehow did not get to the Language Reference - Operators section, so I got excited and jumped over here.)

Paraentheses, yes...that's the way for me to go.

Much appreciated!

Seeya,

frew

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...