KCE Posted February 8, 2010 Share Posted February 8, 2010 (edited) What is the autoit equivalent of C++ break for switch statements? According to AutoIt help, ExitLoop will only break out of a While, Do or For loop. And ContinueLoop doesn't seem to be what I need. I'm thinking I should just use a chain of Else-If's. Edited February 8, 2010 by KCE Link to comment Share on other sites More sharing options...
whim Posted February 8, 2010 Share Posted February 8, 2010 (edited) AFAIK the logic in AutoIt is the reverse of C: you don't need break if you want to leave the Switch after a Case is triggered;if, on the contrary you want the C default, i.e execution continues into the next case, use ContinueCase(from the help file for ContinueCase)Normally in a Select or Switch block, a case ends when the next Case statement is encountered. Executing the ContinueCase will tell AutoIt to stop executing the current case and start executing the next case.HTH,whim Edited February 8, 2010 by whim Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 8, 2010 Share Posted February 8, 2010 (edited) What is the autoit equivalent of C++ break for switch statements? According to AutoIt help, ExitLoop will only break out of a While, Do or For loop. And ContinueLoop doesn't seem to be what I need. I'm thinking I should just use a chain of Else-If's.And how do you think you would "break" out of a chain of ElseIf's?Switch, Select, and If/ElseIf are all conditional logic, not loops. So this whole "break" conversation is a little confusing in that context. Post an example script so we can see what you mean.Edit: Ahh, so! As weaponx pointed out, AutoIt is not C++ and the "break;" is implied at the end of every Case. Edited February 8, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
weaponx Posted February 8, 2010 Share Posted February 8, 2010 AutoIt doesn't need a break statement for conditional functions, each condition is automatically broken. In C++ and php, switch and select will cascade if break is not used, in AutoIt the only way to cascade is by using ContinueCase. Link to comment Share on other sites More sharing options...
KCE Posted February 11, 2010 Author Share Posted February 11, 2010 (edited) What I have in mind is "break" will exit the case on the spot instead of having to wait to reach the end of the case block to actually exit.For example, instead of this:Switch Case 1 If blah = 0 code EndIf Case 2 ... EndSwitch ...I'd rather do this but "break" doesn't exist. If I use ContinueCase it would go to Case 2 which I don't want. What I want "break" to do is to exit the switch statement entirely and execute the last ...Switch Case 1 If blah = 1 Then break EndIf code Case 2 ... EndSwitch ...Another way I could do this is to set a global variable and then have each of the cases do ContinueCase if the global variable is set, but this seems unnecessarily complicated to me.Global x = 0 Switch Case 1 If blah = 1 OR x = 1 Then x = 1 ContinueCase EndIf code Case 2 If blah = 1 OR x = 1 Then x = 1 ContinueCase EndIf ... Case 3 If blah = 1 OR x = 1 Then x = 1 ContinueCase EndIf ... EndSwitch ...Man I miss curly brackets lol. Rather then a nest of if checks I'd rather do a series of if checks. Basically I try not to use too many nests unless I have to. Edited February 11, 2010 by KCE Link to comment Share on other sites More sharing options...
Xand3r Posted February 11, 2010 Share Posted February 11, 2010 Select Case $var = 1 And $blah <> 1 code Case $var = 2 And $blah <> 1 code Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro Link to comment Share on other sites More sharing options...
LondonNDIB Posted January 2, 2015 Share Posted January 2, 2015 (edited) I'm with the OP on this old topic. Of course a break isn't NECESSARY, but then... neither is the Switch at all ( you can do it with a series of IF statements ). The point is easier to read (and write) code. Being able to break out of a case would be useful. In fact, I've thought of it so many times that I finally decided to search and see if there was a way I wasn't seeing. I can (and do) write my code to skirt around this unfortunately missing piece of flow control, but it would be nice if I didn't have to. Please implement a break! Edited January 2, 2015 by LondonNDIB Link to comment Share on other sites More sharing options...
MikahS Posted January 2, 2015 Share Posted January 2, 2015 This was from almost 5 years ago. The last time the author was active, was Feb 15 2010 10:11 PM. Send("{BREAK}") Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
Developers Jos Posted January 2, 2015 Developers Share Posted January 2, 2015 This was from almost 5 years ago. The last time the author was active, was Feb 15 2010 10:11 PM. Send("{BREAK}") .. and your point is ? LondonNDIB is merely stating a case and uses an old topic to add on to. In case you feel a topic needs moderation then refrain from posting and simply report it. Thanks. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
MikahS Posted January 2, 2015 Share Posted January 2, 2015 (edited) No problem, wasn't meant to get everyone into tiff. Just thought if LondonNDIB wanted to have a discussion about this the post should go into the developer chat, where everyone could take part, not in a 5 year old thread (you can see where this logic failed me ha). My apologies. Edited January 2, 2015 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
LondonNDIB Posted January 2, 2015 Share Posted January 2, 2015 (edited) I know some are of the "don't bring up old #$@@!" mind. I am, personally, in the "don't start a new thread when one already exists" camp. If your Send("{BREAK}") was meant seriously... that doesn't really work, does it? Edited January 2, 2015 by LondonNDIB Link to comment Share on other sites More sharing options...
MikahS Posted January 2, 2015 Share Posted January 2, 2015 (edited) It's essentially like sending a CTRL + Break, I don't know if that was exactly what you wanted, but thought you might want to give it a try. It won't hold execution, but the break statement is used with the conditional switch statement and with the do, for, and while loop statements. Essentially the break statement for this language is ExitLoop. EDIT: I know some are of the "don't bring up old #$@@!" mind. I am, personally, in the "don't start a new thread when one already exists" camp. No problem, apologies if you felt attacked. That was not what my intentions were. Edited January 2, 2015 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 2, 2015 Moderators Share Posted January 2, 2015 LondonNDIB, I know some are of the "don't bring up old #$@@!" mind. I am, personally, in the "don't start a new thread when one already exists" campWe generally prefer that you start a new thread and link to the old one if really necessary. We say this for two main reasons: - 1. The language advances and the functionality asked for in old threads might well be included in core or UDF code by now.- 2. The changes in language syntax mean that it is likely that code from more than a couple of years ago may well not run under the current release interpreter without significant modification.I realise that is not the case here, but we would still be grateful if you could try to fit in with our way of doing things. M23 MikahS 1 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...
LondonNDIB Posted January 2, 2015 Share Posted January 2, 2015 Now I know! @Mikah... Switches aren't loops, so exitloop isn't appropriate. Sending the {break} didn't work (didn't think it would but thought I'd try it just in case). I still think an ExitCase (or even ExitSwitch) device would be very handy. Not necessary, no... but cleaner. I've run into a few cases where reversing logic doesn't really work so I'm left with an ugly series of IF statements and $flag variables. Ah well. Link to comment Share on other sites More sharing options...
MikahS Posted January 2, 2015 Share Posted January 2, 2015 (edited) @Mikah... Switches aren't loops, so exitloop isn't appropriate. Sending the {break} didn't work (didn't think it would but thought I'd try it just in case). No problem, I took that line right from the microsoft C++ documentation on break statements. Edited January 2, 2015 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
aleph01 Posted January 3, 2015 Share Posted January 3, 2015 Somewhat off-topic, but I would like to know if nesting if checks is faster than a series of if checks, especially if the series of if checks are one-liners, without the EndIf. Or is the speed difference insignificant?_aleph_ Meds. They're not just for breakfast anymore. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 3, 2015 Moderators Share Posted January 3, 2015 There's no break; but if you setup your select/switch strategically, ContinueCase acts very similar. @eleph01; there have been several tests on speed differences in the example forum. To be honest, I barely remember the outcome, which would mean to me, it's negligible. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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