One of important smart BASIC features is user functions. User functions can work both as functions and as commands.
In program:
Code: Select all
DEF F (X,Y) = SQR (X^2 + Y^2)
A = 3 ! B = 4
PRINT "For catheti";A;"and";B;"hypotenuse is";F (A,B)
User functions can contain several lines:
Code: Select all
DEF F (X,Y)
X2 = X^2
Y2 = Y^2
F = X2 + Y2
END DEF
Code: Select all
'function outputs current time
DEF CUR_TIME
H = CURRENT_HOUR()
M = CURRENT_MINUTE()
S = CURRENT_SECOND()
TEXT CLEAR
PRINT H & ":" & M & ":" & S
END DEF
'infinite loop
LOOP: 'label
CUR_TIME 'function call
PAUSE 1
GOTO LOOP 'going to label
EXERCISE 4
Solve one of previous exercises using user functions.