Page 1 of 1

need example of DEF FUNC usage

Posted: Sun Jun 28, 2015 12:03 am
by greycheek
I would like to see an example of DEF FUNC usage; I'm specifically interested in understanding how to return a value from a function call.

Re: need example of DEF FUNC usage

Posted: Sun Jun 28, 2015 1:58 am
by Dav
You can use RETURN value, to return values from functions, or assign the function name a value when exiting the function. Using RETURN returns the value and then exits the function immediately.

Here is a RETURN example.
This one just returns the number 5, exiting the function.

-----------------------

Print return5

def return5
return 5
Print "this won't show because return used above"
end def

------------------


This function accepts parameters and returns them after using them. It will combine two strings. The function name is assigned a value. Without using RETURN, the function code continues until END DEF.

--------------------

Print combine$("hello ", "world!")

def combine$(first$, second$)
combine$=first$ & second$
'Print "This would show if I wasn't commented out"
End def

-------------------

Hope that helps.

- Dav

Re: need example of DEF FUNC usage

Posted: Sun Jun 28, 2015 2:54 am
by Mr. Kibernetik
greycheek wrote:I would like to see an example of DEF FUNC usage; I'm specifically interested in understanding how to return a value from a function call.
Please read documentation > Basics > User Functions.

Re: need example of DEF FUNC usage

Posted: Sun Jun 28, 2015 12:48 pm
by greycheek
Thanks that helped very much.