A function is similair in mathematics also in IT a mathematical formula, which allocate each X value a Y value.
Also subroutines can be a function, if this routine returns a value (of course in variables). In the Commodore BASIC aren't needed returns with variables, because all variables are used in the whole BASIC program.
10 A = 10: B = 5 20 GOSUB 100 30 PRINT A, B 99 END 100 REM *** Change function *** 101 C = A : A = B : B = C : C = 0: RETURN Screen / output: 5 10
A few special functions, which returns also a numeric value:
- RND used for random numbers
- DEF for defining own mathematical functions and FN for using or starting this definded function
- USR for handover of numbers into a machine language program or back in BASIC out of an assembler routine
- PEEK for peeking a memory adress
- FRE for showing the free (unused) RAM memory in BASIC V2
Also a few functions for string handling or converting:
- Numeric values from chars: ASC, LEN, VAL
- Chars from a number: CHR$, STR$
- Cutting chars or parts of strings from strings: LEFT$, MID$, RIGHT$