Sign in to follow this  
Followers 0

Function Exit Command?

5 posts in this topic

Posted · Report post

Is there a 'function exit' command in Autoit?
I only see "Exit" and "Exitloop"
no exit function or exit sub type command.

Terry

Share this post


Link to post
Share on other sites



Posted · Report post

I think you use return to get out of a function

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

The default action for a Function is to return to the point from which it was called. However you can use an actual Return statement to return a given value to where it was called from.

For $i = 1 To 11
    MsgBox(0, "Return", $i & " is even number:" & "   " & _ChkMod($i))
    _ChkMod_3($i))
    MsgBox(0, "Return", $i & " is even number:" & "   " & _ChkMod_2($i))
Next

Func _ChkMod($iNum)
  If Mod($iNum, 2) = 0 Then Return True
  Return False
EndFunc

Func _ChkMod_2($iNum)
  Local $bMod = False
  If Mod($iNum, 2) = 0 Then $bMod = True
  Return $bMod
EndFunc

Func _ChkMod_3($iNum)
  If $iNum <= 10 Then Return
  MsgBox(0, "", "Goodbye")
  Exit
EndFunc


Edit: Added more functions to show different methods for exiting functions. In this case, when it gets to 11 only the first Value will be displayed Edited by GEOSoft

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

Is there a 'function exit' command in Autoit?
I only see "Exit" and "Exitloop"
no exit function or exit sub type command.

Terry

AutoIT conforms to most other languages (c/java) in this area with the exception of break. There is never a need for a exit function command, you either return a value (which ends the function) or it ends normal when EndFunc is reached.

Edit: just saw George's post. He provides a good example Edited by bo8ster

Share this post


Link to post
Share on other sites

Posted · Report post

I should have added this one too that shows a function working with no explicit return, which is not required because we are operating on a global variable. It should run for ~30 seconds and then exit.

Global $iVal = 0

While 1
    If Mod(@SEC, 5) = 0 Then _SetVal()
    MsgBox(0, "Result", $iVal, 3)
    If $iVal >= 6 Then ExitLoop
WEnd

Func _SetVal()
    $iVal += 1
EndFunc

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  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.