Jump to content

Switch case jumping


Champak
 Share

Recommended Posts

I'm trying to jump to a case if certain conditions are met in a preceding case. I tried coding it like the example below, but it doesn't work. It works up to "case $ccc, $ddd" but it doesn't then jump to "case $hhh". Is there some way to accomplish this?

func something()
    switch $22
        case $aaa, $bbb, $ccc, $ddd, $eee
            switch $22
                case $ccc, $ddd
                    $22 = $hhh
            endswitch
        case $fff
        case $ggg
        case $hhh
            ;Something else here
        case $iii
    endswitch
Endfunc

 

Link to comment
Share on other sites

:unsure:

Global $aaa, $bbb, $ccc, $ddd, $eee, $fff, $ggg, $hhh, $iii, $22
$ccc = "$ccc"
$hhh = "$hhh"
$22  = $ccc

ConsoleWrite("$22=" & $22 & @CRLF)
something()
ConsoleWrite("$22=" & $22 & @CRLF)

func something()
    switch $22
        case $aaa, $bbb, $ccc, $ddd, $eee
            ConsoleWrite(" 1 $22=" & $22 & @CRLF)
            switch $22
                case $ccc, $ddd
                    $22 = $hhh
                    ConsoleWrite(" 2 $22=" & $22 & @CRLF)
                    Return something()
            endswitch
        case $fff
        case $ggg
        case $hhh
            ;Something else here
            $22 = "Something else here"
            ConsoleWrite(" 3 $22=" & $22 & @CRLF)
        case $iii
    endswitch

Endfunc


After a second (or even third) look, this seems like a safer approach to me.

Global $aaa, $bbb, $ccc, $ddd, $eee, $fff, $ggg, $hhh, $iii, $22
$ccc = "Value of ccc"
$hhh = "Value of hhh"
$22  = $ccc

ConsoleWrite("$22=" & $22 & @CRLF)
something()
ConsoleWrite("$22=" & $22 & @CRLF)

Func something()
    Local $bOneMoreTime = True

    While $bOneMoreTime
        $bOneMoreTime = False

        Switch $22
            Case $aaa, $bbb, $ccc, $ddd, $eee
                ConsoleWrite(" 1 $22=" & $22 & @CRLF)
                Switch $22
                    Case $ccc, $ddd
                        $22 = $hhh
                        ConsoleWrite(" 2 $22=" & $22 & @CRLF)
                        $bOneMoreTime = True
                EndSwitch

            Case $fff
            Case $ggg
            Case $hhh
                $22 = "Something else here"
                ConsoleWrite(" 3 $22=" & $22 & @CRLF)

            Case $iii
        EndSwitch
    WEnd
EndFunc

 

Edited by ioa747
UpDate

I know that I know nothing

Link to comment
Share on other sites

maybe this ?

Func something()
    Switch $22      
        Case $aaa, $bbb, $ccc, $ddd, $eee
            ; lines of code here, common to $aaa, $bbb, $ccc, $ddd, $eee then...
            If $22 = $ccc Or $22 = $ddd Then ContinueCase
        
        Case $hhh ; moved here to allow the previous ContinueCase 
            ; lines of code executed when $22 = $ccc or $ddd or $hhh
        
        Case $fff
        Case $ggg
        Case $iii
    EndSwitch
EndFunc

 

Link to comment
Share on other sites

Also another option...

Switch $Var
    Case $Case1, $Case2, $Case3, $Case4 
        ;Do Something here
        If ($Var = $Case3) Or ($Var = $Case4) Then DoSomethingElse($Var)
        
    Case $Case5
        
    Case $Case6
        DoSomethingElse($Var)
        
EndSwitch

Func DoSomethingElse($Var)
    ConsoleWrite(StringFormat("$Var = %s", $Var))
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

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