Introduction to BASIC
DEF statement
DEF statement
We use a DEF statement to define a function using an expression.
Example. 1
100 DEF f(x)=3*x^3-2*x^2+x 110 PRINT f(1),f(2),f(3) 120 END
Example. 2
10 DEF f(x)=3*x^3-2*x^2+x 20 FOR x=0 TO 10 30 PRINT f(x) 40 NEXT x 50 END
Example. 3 This has the same effect as Example. 2
10 DEF f(x)=3*x^3-2*x^2+x 20 FOR a=0 TO 10 30 PRINT f(a) 40 NEXT a 50 END
Example. 4
10 DEF f(x)=3*x^3-2*x^2+x 20 LET x=10 30 PRINT f(1) 40 PRINT x 50 END
x in the DEF line 10 and x in the lines 20 and 40 are distinct variables.
That is, when the line 30 is executed, the line 10 is executed to make x=1, but x in the lines 20 and 40 does not change.
Refer to DEF statement