Jump to content

Func... And Return


Guest Monkey
 Share

Recommended Posts

Guest Monkey

Hello everybody...

This is my first post, so be kind... :D

Global $x
x(1,2)

func x ($a,$b)
$c=$a+$b
If $c=5 then
;c=5
    Return ("1")
    msgbox (0,"","C=5")
Else
;c<>5   
    Return ("0")
    msgbox (0,"","C<>5")
EndIf
EndFunc

I don't really understand the 'Return' issue. Since the msgboxs are not displayed, where the script "goes" once it arrives to the Return command?

Thanks for the help!

Link to comment
Share on other sites

Return exits the function. The program starts again from the line after where the function has been called.

you can assign the func value to a variable and use it, the variable will have the return value.

E.g.

Global $x
$h = x(1,2)

If $h = 0 Then MsgBox(0,"","the function returned 0")
If $h = 1 Then MsgBox(0,"","the function returned 1")

func x ($a,$b)
$c=$a+$b
If $c=5 then
;c=5
Return ("1")
msgbox (0,"","C=5")
Else
;c<>5 
Return ("0")
msgbox (0,"","C<>5")
EndIf
EndFunc
Link to comment
Share on other sites

  • Developers

Return basically means: Stop the function here and return to where it was called from ... optionally with a return value...

Global $x
$rc=x(1,2)
if $rc = 1 then 
  ; c = 5
endif

func x ($a,$b)
   $c=$a+$b
   If $c=5 then
     ;c=5
      msgbox (0,"","C=5")
      Return (1) 
   Else
     ;c<>5 
      msgbox (0,"","C<>5")
      Return (0) 
   EndIf
EndFunc

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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