ExitFunction
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(X)




     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 data (values / strings or arrays) can be used as complete statements. For example,

MyOtherFunction()


     calls the MyOtherFunction routine.

     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:


      * ExitFunction can only be used from within a function block, and doesn't work from within protected subroutines (Psub/EndPsub block).

      * Any return data (values/strings or arrays) that follow ExitFunction must be of the same type and number of those following the EndFunction statement.

      * You can return multiple values from a function using ExitFunction, but the number of parameters following the ExitFunction statement.

      * See the Functions&PSub tutorial in the About section of the help for more details




Mini Tutorial:




  
; 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: EndFunction | Function | Functions&Psub | Psub :
 


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