need example of DEF FUNC usage

Post Reply
User avatar
greycheek
Posts: 34
Joined: Sun Mar 15, 2015 3:14 pm
My devices: MacBook Air, Iphone 6+, Ipad 2

need example of DEF FUNC usage

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

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: need example of DEF FUNC usage

Post 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

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: need example of DEF FUNC usage

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

User avatar
greycheek
Posts: 34
Joined: Sun Mar 15, 2015 3:14 pm
My devices: MacBook Air, Iphone 6+, Ipad 2

Re: need example of DEF FUNC usage

Post by greycheek »

Thanks that helped very much.

Post Reply