Jump to content
Sign in to follow this  
Hawk

Understand "And"

Recommended Posts

Hawk

Topic name should be [understanding "And"], can't I change it?

I heard that in other languages like C it's in general like this (or only with code optimization, i don't know), that only so many conditions connected with "And" are checked, until one condition is not met.

Example:

If $a = 1 And $b = 2 And $c = 3 And $d = 5 Then
    ...
EndIf

Are all 4 variables checked here always? Or only until one condition is not true? If, then from which side? From left to right (first $a, then $b...) or from right to left (first $d, then $c...)?

And can I tell AutoIT to optimize it on demand?

If I am only checking some variables, I want to only check them until one condition is not true to save processing time.

But in another case where I call a function that also changes variables, I want to check ALL conditions so each function is also processed!

Example:

If WinMove("win1", "", 100, 100) And WinMove("win2", "", 500, 500) Then
    ...
EndIf
Edited by Hawk

Share this post


Link to post
Share on other sites
Melba23

Hawk,

As I understand it AutoIt evaluates multiple AND expressions left to right until one of them returns False. OR works similarly and the evaluation ends as soon as an expression returns True. The order is as set by you when the condition is coded and is not "optimizable". :oops:

If you want to run all your functions then I suggest you run them first assigning the return value to a variable and then check those variables in the multiple AND statement like this: :bye:

$Win_1 = WinMove("win1", "", 100, 100)
$Win_2= WinMove("win2", "", 500, 500)

If $Win1 And $Win2 Then
    ...
EndIf

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Hawk

Thanks once again Melba23 :oops:

I guess in a switch-case-statement values are checked from up to down?

Switch $a
    Case 3
        ...
    Case 4
        ...
EndSwitch

So $a is first checked for 3, and only for 4 if it is not 3, right?

And a little bit offtopic, but here is a small example:

Global $a = 4
Select
    Case $a = 4
        MsgBox(0, "", "4")
    Case $a = 5
        MsgBox(0, "", "5")
    Case Mod($a, 4) = 0
        MsgBox(0, "", "var % 4 = 0")
EndSelect
Exit 0

How would I let a select statement check for all cases? Here the script only shows one messagebox, where it should really show two. If $a is 4, the second messagebox will never pop up.

Can this be done?

Share this post


Link to post
Share on other sites
JohnOne

If the expression is true the following statements up to the next Case or EndSelect statement are executed. If more than one of the Case statements are true, only the first one is executed.

EDIT:

Try ContinueCase after the conditional statements.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Melba23

Hawk,

Again with the proviso that this is only my understanding, you are correct about Switch and Select structures working from top to bottom. And they only action a single Case - so if you want to check the Mod value you will need another structure: :oops:

Global $a = 4
Switch $a
    Case 4
        MsgBox(0, "", "4")
    Case 5
        MsgBox(0, "", "5")
EndSwitch
Switch Mod($a, 4)
    Case  0
        MsgBox(0, "", "var % 4 = 0")
EndSwitch
Exit 0

M23

Edit:

JohnOne,

ContinueCase just runs the code for the next Case, it does not evaluate the condition. It can be quite useful when exiting - like this:

Switch $iVar
    ; Save and exit
    Case 1
        ; Do saving of vars etc here
        ContinueCase
    ; Exit directly
    Case 0
        ; Clean up code goes here and is run in both cases
        Exit
EndSwitch
Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
JohnQSmith

ContinueCase just runs the code for the next Case, it does not evaluate the condition.

That is interesting. I did not know this. I thought it was removing the "C++ break" statement from the case allowing the switch to continue parsing instead of breaking out. I'm going to have to revisit my code.


Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Share this post


Link to post
Share on other sites
Hawk

I see.. I thought it can be done somehow in one 'select'. But luckily I won't need that often. Thanks for the answers!

Share this post


Link to post
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
Sign in to follow this  

×