Jump to content

Recommended Posts

Posted

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

ย 

Posted (edited)

: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

Posted

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

ย 

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Posted

Hi @Champakย ๐Ÿ‘‹ ,

the answers are all fine.
My 2 Cents for such things: Try to avoid such nested case handling at all.

Maybe the usage of polymorphism can help you. And yes, I know, AutoIt is not OOP based, but the approach of polymorphism is adaptable ๐Ÿ˜€ .

Best regards
Sven

==> AutoIt related: ๐Ÿ”— GitHub, ๐Ÿ”— Discord Server, ๐Ÿ”— Cheat Sheet

Spoiler

๐ŸŒย Au3Forums

๐ŸŽฒ AutoIt (en) Cheat Sheet

๐Ÿ“Š AutoIt limits/defaults

๐Ÿ’Ž Code Katas: [...] (comming soon)

๐ŸŽญ Collection of GitHub users with AutoIt projects

๐Ÿžย False-Positives

๐Ÿ”ฎย Me on GitHub

๐Ÿ’ฌย Opinion about new forum sub category

๐Ÿ“‘ย UDF wiki list

โœ‚ย VSCode-AutoItSnippets

๐Ÿ“‘ย WebDriver FAQs

๐Ÿ‘จโ€๐Ÿซย WebDriver Tutorial (coming soon)

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
  • Recently Browsing   0 members

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