Contents / Reference section / BASIC keywords / Previous letter / Next letter / Index
Sometimes the computer has to decide whether or not something is true. For example:
10 X=12
20 IF X=20 THEN PRINT "X EQUALS 20"
clearly, in this example, the statement X=20 is false. As a result the program will never print X EQUALS 20.
100 X=12
110 REPEAT
120 PRINT "HELLO"
130 UNTIL X=20
would repeatedly print HELLO because X will never be anything else than 12. X=20 is FALSE. The same effect can be achieved by writing.
110 REPEAT
120 PRINT "HELLO"
130 UNTIL FALSE
which means, repeat for ever.
In fact, the computer has a numerical value of FALSE, which is zero. Thus
PRINT FALSE
will print 0.
Similarly
PRINT 5=4
will also print 0, since 5=4 is false.
It is often useful to say in a program for example
CLOCKSET=FALSE
and then later one can say
IF CLOCKSET THEN PRINT "THE CLOCK IS CORRECT"
100 oldenough = FALSE
245 UNTIL FALSE
A function returning the value zero.
<num-var>=FALSE
TRUE
FN preceding a variable name indicates that it is being used as the name of a function. Both string and numeric functions may be defined. See the keyword DEF on page 230 and for a more detailed description of functions and procedures.
Since a function always returns a value it often appears on the right of an equals sign or in a print statement. Procedures, on the other hand do not return results.
1000 DEF FNmean2(x,y)=(x+y)/2
A reserved word used at the start of all user-defined functions.
DEF FN<variable-name>[(<num-var>|<str-var>{,<num-var>|<str-var>})]
ENDPROC, DEF, LOCAL
The word FOR is one of the words used in a FOR...NEXT loop. This makes the computer execute a series of statements a specified number of times; for example:
120 FOR X=1 TO 5
130 PRINT X
140 NEXT X
would print out the numbers 1,2,3,4,5.
The variable X in the above example initially takes on the value 1 and the program then goes through until it reaches the word NEXT. The program then returns to the line or statement
FOR X=1 TO 5 and X is increased in value by 1. The program continues the loop, increasing the value of X in steps of 1, until X reaches 5. After that, the program no longer loops; instead it moves onto the next statement after the
FOR ... NEXT loop.
As an option the "step size" can be changed. In the example above X increased by 1 each time around the loop. In the next example XYZ increases by 0.3 each time around the loop.
230 FOR XYZ=5 TO 6 STEP 0.3
240 PRINT XYZ
250 NEXT XYZ
The above program would print out the numbers
5
5.3
5.6
5.9
The value of XYZ on exit from the above program would be 6.2
The step size may be negative if you wish to make the value of the "control variable" decrease each time around the loop.
870 FOR r2d2%=99 TO 60 STEP -12
880 PRINT r2d2%; " Hi there"
890 NEXT r2d2%
would print
99 Hi there
87 Hi there
75 Hi there
63 Hi there
The FOR...NEXT loop always executes once so
FOR D=5 TO 3: PRINT D: NEXT D
would print 5 and then stop.
300 FOR X=1 TO 16 STEP 0.3: PRINT X: NEXT X
1040 FOR A%=0 TO MAXIMUM%
560 FOR TEMPERATURE=0 TO 9
A statement initialising a FOR...NEXT loop. This structure always executes at least once. Any assignable numeric item may be used as the control variable but integer control variables are about three times faster than real variables.
FOR <num-var>=<numeric> TO <numeric> [STEP <numeric>]
TO, STEP, NEXT