DEF FN
This page was last modified 01:05, 5 December 2016 by Mars2000you. Based on work by Gdx and Kanima and others.

Contents

Effect

Define a function which returns user-specified output based on optional variables.

Syntax

DEF FN <name> [(<variable>[,<variable>]...)=<expression>

Parameters

<name> is the function name, the length of the function name can be as long as you want, only the first two characters of the function name will actually be used.

Furthermore, if a function is to return a string, the name of the function has to be suffixed by a $.

<variable> is optional , it is an alphanumeic variable that will be used in the <expression>. Several variables can be specified, they must be separated by a comma. It's only useful to define the function. The variables don't have any influence on the variables with the same name in the main program.

<expression> is the function itself. It can use variables that are not specified in the <variable> part, but have already a value in the main program.

Example

10 DEF FN SQUARE (X)=X^2
20 PRINT "The square of 2 is ";FN SQUARE(2)
30 PRINT "The square of 4 is ";FN SQUARE(4)
 
RUN
The square of 2 is  4
The square of 4 is  16

Related to

CLEAR

Compatibility

MSX-BASIC 1.0 or higher