Defines a function.
DEF FNname [ (argument_list) ] = expression`
DEF FNname [ (parameter_list) ]
…
FNname = expression
…
END DEF
Function names must beging with FN and can contain up to 40 characters. The function name indicates the value type the function returns:
| Function Name | Returns |
|---|---|
FNday$ |
string |
FNcount% |
integer |
FNaverage# |
single-preceision value |
For a function to return a value, the function must assign its result to the function name.
argument_list is a list of parameters to the function separated by commas as follows:
argument_name [ AS type ]
You cannot use a function before your program defines it, nor can you use DEF FN functions recursively.
DEF FNsum (a AS INTEGER, b AS INTEGER) = a + b
DEF FNmax (a AS INTEGER, b AS INTEGER, c AS INTEGER)
IF (a > b) THEN
max = a
ELSE
max = b
END IF
IF (max > c) THEN
FNmax = max
ELSE
FNmax = c
END IF
END DEF
PRINT FNsum(3, 5)
PRINT FNmax(1, 2, 3)
Running this program produces the following:
8
3