Jump to content

Conditional processing order


Bowmore
 Share

Recommended Posts

Does anyone know if AutotIt uses short circuit logic when testing for multiple conditions.

For example in the following code:

If foo1() = True and foo2() = True and foo3() = True Then
    Do Stuff
EndIf

If foo3() returned False would the processing jump to the first line after the EndIf statement without evaluating foo1() and foo2() or will foo1() and foo2() be always processed.

Knowing the answer to this can be a great help when optimising condition checking within loops especially when you have some prior knowledge of the probability of each condition occurring.

Thanks

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Well, about 10 more lines of example code and you could have tested this yourself by just using simple functions with MsgBox() in them. But the answer is yes, AutoIt short circuits conditional statements.

Thanks for answering my dumb question Valik.

I realised shortly after posting that I could easily have check this out for myself.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

  • Administrators

Erm, it does, but not as you posted in your example. It evaluates left to right in that line. If foo1 or foo2 were false then it would never get to call foo3. You seemed to be asking if foo3 was tested first?

Link to comment
Share on other sites

btw about if evaluation.

Sometimes I doubt real assignment will be carried out:

dim $Var = 0

if $Var = 10 then

; <some expression>

endif

and to be assured think about other form:

dim $Var = 0

if 10 = $Var then

; <some expression>

endif

:)

The point of world view

Link to comment
Share on other sites

btw about if evaluation.

Sometimes I doubt real assignment will be carried out:

dim $Var = 0

if $Var = 10 then

; <some expression>

endif

and to be assured think about other form:

dim $Var = 0

if 10 = $Var then

; <some expression>

endif

:)

While that is a fairly common practice in C\C++, it's not necessary in AutoIt. If statements do not perform assignment. That code does not translate to "assign $Var equal to 10, evaluate boolean value of 10" which it would do in C\C++.
Link to comment
Share on other sites

Erm, it does, but not as you posted in your example. It evaluates left to right in that line. If foo1 or foo2 were false then it would never get to call foo3. You seemed to be asking if foo3 was tested first?

Thanks Jon.

Yes I had been making the wrong assumption that the parts would be evaluated right to left.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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...