User Tools

Site Tools


en:function

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
en:function [2016/01/01 22:41]
127.0.0.1 external edit
en:function [2016/08/12 13:01]
admin
Line 3: Line 3:
 ==== Format ==== ==== Format ====
 **function** function_name ( //variable_list// )\\ **function** function_name ( //variable_list// )\\
-(tab)//statements//\\ +(tab)[[programsyntax|statement(s)]]\\
-**end function** +
- +
-**function** function_name$ //variable_list// )\\ +
-(tab)//statements//\\+
 **end function** **end function**
  
 ==== Description ==== ==== Description ====
-Create a function that will receive zero or more values, process those values and return either a numeric or string value.  Return values are set by assigning the name of the function and executing a [[Return|Return]] statement or allowing the //End Function// statement to be executed.  All variables used within the function will be local to the function and will not change the values in the calling code+Create a function that will receive zero or more values, process those values and return either a value.  Strings, integers, and floating point numbers may be returned by function and are returned by executing a [[Return|Return]] statement with a value ovby assigning the name of the function a value and allowing the //End Function// statement to be executed.  All variables used within the function will be local to the function and will not change the values in the calling code.
- +
-In many structured languages the return value of a function is set using the [[return|Return]] statement.  In BASIC-256 the returned value of a function is set by assigning the function name the value and either executing the [[Return|Return]] statement or reaching the end of the function.  A numeric function has the default return value of zero (0) and a string function has the default value of a zero length string ("").+
  
-Subroutine variables may a list of zero or more, comma separated, numeric or string variables.  Arrays and variables may be passed by reference using the [[Ref|Ref]] definition.+Function variables may a list of zero or more, comma separated, variables.  Arrays and variables may be passed by reference using the [[Ref|Ref]] definition.
  
-Functions should be defined at the bottom of your program, and can not be defined within another function, [[Subroutine|Subroutine]] or control block ([[if|If/Then]], [[do|Do/Until]], ...)+Functions can be defined anywhere in your program, and can not be defined within another function, [[Subroutine|Subroutine]] or control block ([[if|If/Then]], [[do|Do/Until]], ...)
  
 ==== Example ==== ==== Example ====
  
 <code> <code>
-print double$("Hello")+print double("Hello"
 +print double(9)
 print triple(3) print triple(3)
 end end
  
-function double$(a$+function double(a) 
-   double= a+ a$+   double = a + a
 end function end function
  
 function triple(b) function triple(b)
-   triple = b * 3 +   return b * 3
-   return +
-   triple = 9999 # code never gets executed+
 end function end function
 </code> </code>
Line 39: Line 32:
 <code> <code>
 HelloHello HelloHello
 +18
 9 9
 </code> </code>
Line 46: Line 40:
 ==== History ====  ==== History ==== 
 |0.9.9.1|New To Version| |0.9.9.1|New To Version|
 +|1.99.99.|Removed variable/function type|
en/function.txt · Last modified: 2020/02/28 10:46 (external edit)