Jump to content

Is it possible to end a function early?


Recommended Posts

Is it possible to send a function some sort of exit or return flag if a condition is met in the middle of it? I know i could create an if flag that would prevent the rest of the function from running however that doesn't seem a clean way to deal with the problem...

Trying to search the help file for things like function end | function return | function exit is just coming up with an endless amount of off topic results <_<

Don't let that status fool you, I am no advanced memeber!

Link to comment
Share on other sites

Just use a return statement.

edit: I skimmed what you wrote. You want something that's less "sloppy" than an if statement with a return statement inside? I think that's about as neat as it gets.

Edited by Nevin
Link to comment
Share on other sites

Is it possible to send a function some sort of exit or return flag if a condition is met in the middle of it? I know i could create an if flag that would prevent the rest of the function from running however that doesn't seem a clean way to deal with the problem...

Trying to search the help file for things like function end | function return | function exit is just coming up with an endless amount of off topic results <_<

i guess im failing to find an example of a return statement inside a function (assuming its the same type of logic as a return in say php) atm the only way i have of stopping the rest of a function from running is by creating a flag and then encapsulating the rest of the function within an if statment that runs if that flag isn't set :) ((thats the part i was calling sloppy))

lol ok i feel stupid.... since return() always syntax errors k.i.s.s'ing it worked lol

$foo = 5

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
    if $foo == 5 Then
    ; stop function here....
        return
    EndIf
    MsgBox(4096,"","This is a message that should only run if $foo != 5...")
EndFunc

Don't let that status fool you, I am no advanced memeber!

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...