Jump to content
Sign in to follow this  
Champak

Exit nested if...but stay in the function

Recommended Posts

Champak

I don't want to have to restructure a particular function, so I was wondering if it was possible to get out of a IF condition within a function, BUT continue on with the function.

Ex.

Func ...

    IF something then
           blah blah
    Endif

    If something 2 then
           blah blah 2
                If something 3 then
                        exit this if condition AND "something 2" because of whatever reason;<-----------
                Endif
    endif

    ;Continue on within the function

endfunc
Edited by Champak

Share this post


Link to post
Share on other sites
Valuater

Absolutely, Yes!

( based on good code )

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
-Ultima-

You're probably going to need to store some kind of boolean along the lines of:

Func
    If $something Then
        ;whatever
    EndIf

    Local $inner_exit = False
    If $something_2 then
        ; blah
        If $something_3 Then
            ; reach some condition, set $inner_exit = True
        EndIf

        If Not $inner_exit Then
            ; Rest of $something_2 block
        EndIf
    EndIf

    ; Rest of function
EndFunc

It's ugly, and can probably be rearranged slightly (depending on what you're trying to do), but that's the general gist of it. This kind of situation is one of the rare times that goto statements can be useful (at least for writing nicer code), but they're not entirely necessary.

Edited by -Ultima-

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

Share this post


Link to post
Share on other sites
Champak

@ -Ultima-

Thanks, I thought of that, I was just hoping there was something "simpler" than that like "ReturnIF" that I didn't see or some other type of function to interject. But I guess I'll go back to that. Thanks.

Edited by Champak

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  

×