Jump to content

Exit from Switch...Case


 Share

Go to solution Solved by Exit,

Recommended Posts

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

  • Solution

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

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
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

Edited by mike2003
Link to comment
Share on other sites

  • Moderators

mike2003,

Interesting find. :thumbsup:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

  • 4 months later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...