Hawk Posted March 6, 2012 Share Posted March 6, 2012 (edited) 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 ... EndIfAre 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 March 6, 2012 by Hawk Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 6, 2012 Moderators Share Posted March 6, 2012 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". 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: $Win_1 = WinMove("win1", "", 100, 100) $Win_2= WinMove("win2", "", 500, 500) If $Win1 And $Win2 Then ... EndIfM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Hawk Posted March 6, 2012 Author Share Posted March 6, 2012 Thanks once again Melba23 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? Link to comment Share on other sites More sharing options...
JohnOne Posted March 6, 2012 Share Posted March 6, 2012 (edited) 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 March 6, 2012 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 6, 2012 Moderators Share Posted March 6, 2012 (edited) 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: 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 0M23Edit: 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 March 6, 2012 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnQSmith Posted March 6, 2012 Share Posted March 6, 2012 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". Link to comment Share on other sites More sharing options...
Hawk Posted March 6, 2012 Author Share Posted March 6, 2012 I see.. I thought it can be done somehow in one 'select'. But luckily I won't need that often. Thanks for the answers! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now