AutoIt equivalent of C++ break?

17 posts in this topic

KCE 0

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.

Share this post

Link to post

Share on other sites

PsaltyDS 24

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.

Share this post

Link to post

Share on other sites

weaponx 8

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.

Share this post

Link to post

Share on other sites

KCE 0

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

Share this post

Link to post

Share on other sites

Xand3r 0

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

Share this post

Link to post

Share on other sites

LondonNDIB 0

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.

Share this post

Link to post

Share on other sites

MikahS 92

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

Share this post

Link to post

Share on other sites

MikahS 92

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.

Share this post

Link to post

Share on other sites

Melba23 2,461

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

We 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

1 person likes this

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

Share this post

Link to post

Share on other sites

LondonNDIB 0

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

Share this post

Link to post

Share on other sites

aleph01 15

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?