en:function [BASIC 256 - Language Documentation]

# BASIC 256 - Language Documentation

en:function

## Function (Statement)

### Format

function function_name ( variable_list )
statements
end function

function function_name$ ( variable_list )
statements
end function

### 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 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.

In many structured languages the return value of a function is set using the 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 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 definition.

Functions should be defined at the bottom of your program, and can not be defined within another function, Subroutine or control block (If/Then, Do/Until, …)

### Example

    print double$("Hello")
    print triple(3)
    end
    function double$(a$)
       double$ = a$ + a$
    end function
    function triple(b)
       triple = b * 3
       return
       triple = 9999	# code never gets executed
    end function

will display

    HelloHello
    9

### See Also

Begin Case / Case / End Case, Call, Continue Do, Continue For, Continue While, Do / Until, End, Exit Do, Exit For, Exit While, For / Next, Function, Global, Goto, Gosub, If Then, Pause, Ref, Rem, Return, Subroutine, While / End While

### History

0.9.9.1 | New To Version

en/function.txt · Last modified: 2014/02/08 22:50 by admin