need example of DEF FUNC usage
need example of DEF FUNC usage
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.
			
			
									
									
						- 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
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
			
			
									
									
						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
- Mr. Kibernetik
 - Site Admin
 - Posts: 4794
 - Joined: Mon Nov 19, 2012 10:16 pm
 - My devices: iPhone, iPad, MacBook
 - Location: Russia
 - Flag: 

 
Re: need example of DEF FUNC usage
Please read documentation > Basics > User Functions.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.
Re: need example of DEF FUNC usage
Thanks that helped very much.