# Conditional processing order

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

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

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

##### 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?

##### Share on other sites

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

##### Share on other sites

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

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

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...