EndFunction
Function <.FuncName.>[(ParamList)] ... [ExitFunction] ... EndFunction
 
Parameters: NONE
Returns: NONE
 

     Functions can be called from different locations in a program. A function is a routine that returns a value after it executes. For example:

I = MyFunction()



     calls MyFunction and assigns the result to I. Function calls cannot appear on the left side of an assignment statement. Functions that don't return a value can be used as complete statements. For example,

MyOtherFunction()


     calls the MyOtherFuntion routine. Functions can call themselves recursively.


     A function is declared with the Function keyword, followed by the function name and a list of optional parameters (seperated my commas). The function ends with the EndFunction statement that can be followed by a value or expression that will be returned. With ExitFunction you can exit a function anywhere in the function block.



FACTS:


      * To return information from a function, the variables & arrays need to be listed after the EndFunction statement. ie. EndFUnction Result would return the value of the Result variable back to the caller.

      * For style reasons, Function declaration keywords (Function & EndFunction) can not be indented.

      * Values or expressions that follow EndFunction and ExitFunction must be of the same type.

      * You can return multiple values from a function.

      * Need more information on functions ? See the Functions&Psub tutorial. Also, See the ArrayBasics, Types tutorials for passing arrays & types.




Mini Tutorial:


The follow code contains variable example functions. We have a function that doesn't

  
; A Function that does Not Return a value
Function NoReturnValue()
  Print "This function doesn't return anything"
EndFunction
  
; A function that conditionally exits
Function ExitEarly(AValue)
  If AValue = 5 Then Exitfunction "I exit early"
EndFunction "I exit late"
  
; A function that returns three values
Function MoreReturnValues()
  Life = 42
  Name$ = "Deep Thought"
EndFunction Life, Name$, 4.321
  
; Call the Functions
  NoReturnValue()
  Print ExitEarly(1)
  Print ExitEarly(5)
  MyLife, MyName$, MyFloatValue# = MoreReturnValues()
  
  Print MyLife
  Print MyName$
  Print MyFloatValue#
  
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  




This example would output.

  
  This Function doesn't Return anything
  I Exit late
  I Exit early
  42
  Deep Thought
  4.321
  

 
Related Info: EndPsub | ExitFunction | Function | Functions&Psub | Psub :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com