Jump to content

Operator (| and ||)


Recommended Posts

Hi,

maybe this has been answered before, but I didn't really find it. Sorry for that. :">

Could someone please explain to me, when does Autoit stop checking an OR-condition?

I mean in Java there is a difference between | and ||.

If the first condition is true, it could jump out. Or does Autoit check every or again?

How can I say Autoit to not doing all the ckecks, if it does?

CODE
; |, ||

Global $digits[5] = ['4', 2, 4, 6, 8]

_calc1()
_calc2()

Func _calc1()
    $b = TimerInit()
    If $digits[1] < $digits[2] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] Or $digits[1] < $digits[4] _
            Then ConsoleWrite(TimerDiff($B) & @CRLF)
EndFunc   ;==>_calc1

Func _calc2()
    $b = TimerInit()
    If $digits[3] < $digits[4] Then ConsoleWrite(TimerDiff($B) & @CRLF)
EndFunc   ;==>_calc2

Again sorry for that question, but I do not get it.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

easy to check....

Global $funcs = ""

Func t1()
    $funcs = $funcs & "T1,"
    Return False
EndFunc

Func t2()
    $funcs = $funcs & "T2,"
    Return True
EndFunc

Func t3()
    $funcs = $funcs & "T3,"
    Return True
EndFunc

If t1() OR t2() OR t3() Then
    MsgBox(0,"","The End: Have been in funcs: " & $funcs)
EndIf

As you can see, AutoIT 3.2.2.0 stops as soon as the OR condition evluates True.

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

HI,

thanks I see. And how do I tell Autoit to check with the other option?

Global $funcs = ""

Func t1()
    ConsoleWrite(1 & @CRLF)
    $funcs = $funcs & "T1,"
    Return False
EndFunc   ;==>t1
Func t2()
    ConsoleWrite(2 & @CRLF)
    $funcs = $funcs & "T2,"
    Return False
EndFunc   ;==>t2
Func t3()
    ConsoleWrite(3 & @CRLF)
    $funcs = $funcs & "T3,"
    Return True
EndFunc   ;==>t3
Func t4()
    ConsoleWrite(4 & @CRLF)
    $funcs = $funcs & "T4,"
    Return True
EndFunc   ;==>t4
Func t5()
    ConsoleWrite(5 & @CRLF)
    $funcs = $funcs & "T5,"
    Return True
EndFunc   ;==>t5
Func t6()
    ConsoleWrite(6 & @CRLF)
    $funcs = $funcs & "T6,"
    Return True
EndFunc   ;==>t6
Func t7()
    ConsoleWrite(7 & @CRLF)
    $funcs = $funcs & "T7,"
    Return False
EndFunc   ;==>t7
Func t8()
    ConsoleWrite(8 & @CRLF)
    $funcs = $funcs & "T8,"
    Return True
EndFunc   ;==>t8

If t1() Or t2() Or t3() Or t4() Or t5() Or t6() Or t7() Or t8() Then
    MsgBox(0, "", "The End: Have been in funcs: " & $funcs)
EndIf

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

thanks I see. And how do I tell Autoit to check with the other option?

what other option?

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

what other option?

HI,

like mentioned in the topic. Either this | or this || the the different behaviour.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

HI,

like mentioned in the topic. Either this | or this || the the different behaviour.

So long,

Mega

Neither of the operators exist.

Regarding the topic question "When does Autoit stop checking?": I think we have an answer, right?

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Neither of the operators exist.

Regarding the topic question "When does Autoit stop checking?": I think we have an answer, right?

Hmmh, sorry my English is not very good - that is why I'm struggeling to show you what I mean.

One more try:

In Java there are this operators | and || both for the or condition.

If I make an If with 100 or like

If a>b | a>c | .... Then ...

Java stops checking after the first condition is true, right?

If I make it this way

If a>b || a>c || ... Then ...

Java will check every condition, right?

So, how to accomplish the two behaviours in Autoit?

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

oiy!

AutoIt defualty uses 'short circut evaluation'... don't think you can turn that off...in vb for example it's always off unless you force it on ( http://support.microsoft.com/kb/817250 )

but for autoit you may have to make custom check functions or restructure your code so it doesnt rely on the test of a certian condition

There is no keyword to make it act differently, use a custom check function or redo your code so it doesn't need it
Link to comment
Share on other sites

There is no keyword to make it act differently, use a custom check function or redo your code so it doesn't need it

Hi,

congrats for 300 posts!

Okay, when this is the way Autoit works.

Thanks!

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hmmh, sorry my English is not very good - that is why I'm struggeling to show you what I mean.

So, how to accomplish the two behaviours in Autoit?

I know what you want, but as I said, that's not directly possible in AutoIT and I don't see the need for it.

If you do what you have shown in your code (just compare variables) than it makes no sense at all to test every equation in an OR clause. As soon as the first one is true the whole if statement will be true and will no change, no matter what comes later. That's the nature of the OR operator. If one term evaluates to true, then the whole term will be true, so it's a matter of saving time if the checking stops.

The only thing where it might be usefull if you do assignments or function calls in the if statement (like my code). Then it might be important that all functions get called, as they could possibly set or change things. But in general that's not good programming style, as nobody will ever be able to understand those side effects after a while.

However, there are ways to "simulate" that behaviour in AutoIT, although it really makes no sense to do that!

$bool1 = 1 > 2
$bool2 = 2 > 1
$bool3 = func1()
$bool4 = func2()

if $bool1 or $bool2 or $bool3 or $bool4 then _do_whatever()

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

I'm having problems thinking here but couldn't you just put store the result from the expressions in variables,

where then all expressions will be executed, and after that check the variables in a If-statement ?

$func1 = func1()
$func2 = func2()
$math1 = (1 + 5 = 8)
$math2 = (6 + 3 = 9)

If $func1 OR $func2 OR $math1 OR $math2 Then MsgBox(64, "", "yep")

EDIT : multitasking slows me down :/

Edited by Helge
Link to comment
Share on other sites

Hi,

thanks! I wasn't searching for examples. Firstly, I wanted to know whether Autoit checks all conditions or stops checking after the first one returned TRUE.

--> Answer Yes, it does stop checking after first TRUE. (Could be something for the helpfile)

Secondly, I wanted to know whether there is an operator like || in Java.

--> Answer No, there isn't something like that.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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