Sign in to follow this  
Followers 0
mike2003

Exit from Switch...Case

12 posts in this topic

Are there commands to interrupt the current CASE block?

Switch $a
    Case 1
        .....
    Case 2
        ....
    if .... then "EXIT"
        ....
    Case 3
        .....
EndSwitch

Share this post


Link to post
Share on other sites



mike2003,

The easiest way is to reverse the logic like this: ;)

Switch $a
    Case 1
        .....
    Case 2
        ....
    If Not .... Then
        ; Do something
    ; Else                   ; These lines are virtual
        ; Exit the Switch    ; and do not need to appear
    EndIf
        ....
    Case 3
        .....
EndSwitch
All clear? :)

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

I know.
I'm interested in commands such Next or Continue or Break.
I could not find, but I think before I do that... Now I can not remember

Share this post


Link to post
Share on other sites

ContinueCase ?

Share this post


Link to post
Share on other sites

Continuecase  continues with the next case statement.

There is a exitcase statement missing in the language.

$i = 2
Switch $i
    Case 1
        MsgBox(262144, Default, "1", 0)
    Case 2
        MsgBox(262144, Default, "2", 0)
        ContinueCase
        MsgBox(262144, Default, "after continuecase", 0)
    Case 3
        MsgBox(262144, Default, "3", 0)
EndSwitch

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

A circumvention: Using case xx twice in conjunction with continuecase.

Works as exitcase.

 

 

$i = 2
Switch $i
    Case 1
        MsgBox(262144, Default, "1", 0)
    Case 2
        MsgBox(262144, Default, "2", 0)
        ContinueCase  ; skip to next case statement
        MsgBox(262144, Default, "after continuecase", 0)
    Case 2 ; same case as above with no operation
    Case 3
        MsgBox(262144, Default, "3", 0)
EndSwitch

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

It's strange, but it seems it works

        Case $Button1
            GUICtrlSetData($Button1, "A")
            Case $Button1 ; Like "BREAK CASE"

            GUICtrlSetData($Button1, "B")
        Case $Button2

"continuecase" not needed

Edited by mike2003

Share this post


Link to post
Share on other sites

mike2003,

Interesting find. :thumbsup:

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

It's strange, but it seems it works

        Case $Button1
            GUICtrlSetData($Button1, "A")
            Case $Button1 ; Like "BREAK CASE"

            GUICtrlSetData($Button1, "B")
        Case $Button2
"continuecase" not needed

 

 

It is not strange, but normal behavior. Just Tidy the script.

Case $Button1
            GUICtrlSetData($Button1, "A")
        Case $Button1 ; this is the same "case". 
                      ; it will not be executed. See Help. 
                      ; "If more than one of the Case statements are true, only the first one is executed."

            GUICtrlSetData($Button1, "B")
        Case $Button2

There is no "Break Case" and no conditional processing.

Here a solution, where a conditional "Break case" is used.

$i = 1
$sw = InputBox("", "Enter 0 or 1", "0")
Switch $i
    Case 1
        If $sw = "1" Then ContinueCase ; skip to next case statement
        MsgBox(262144, Default, "Switch is off", 0)
    Case 1
        MsgBox(262144, Default, "Switch is on", 0)
EndSwitch

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Looks like it works too! ContinueLoop

Case $Button4
    PrintMessage("OK4-1")
    if (1) Then ContinueLoop ;"BREAK CASE"
    PrintMessage("OK4-2")
Edited by mike2003

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