A RAGBAG OF FUNCTIONS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

This chapter covers all those statements and functions that haven't already been dealt with elsewhere.
20 DIM A(A) Each element is referred to by its subscript. For instance B(0) is the first element of array B B(2) is the third element of array B B(N) is the (N+1)th element of array B. Because you can use any integer expression as a subscript it is possible to process array elements easily and quickly. Here is an example of the use of arrays for character manipulation. CHEESE NIBBLER 10 DIM A(10) 20 DIM B(10) 30 DIM C(10) 100 FOR J = 1 T0 10 110 LET A(J)=1 120 LET B(J)=1 130 LET C(J)=1 140 NEXT J 200 FOR J=1 T0 10 205 IF NOT A(J) = 1 THEN GO TO 220 210 PRINT "•"; 215 GO TO 230 220 PRINT ""; 230 NEXT J 240 PRINT 300 FOR J=1 T0 10 305 IF NOT B(J) = 1 THEN GO TO 320 310 PRINT ""; 315 GO TO 330 320 PRINT ""; 330 NEXT J 340 PRINT 400 FOR J=1 T0 10 410 PRINT "•": 415 GO TO 430 420 PRINT ""; 430 NEXTJ 440 PRINT 445 PRINT "HIT NEWLINE TO NIBBLE THE CHEESE" 450 INPUT Y$ 460 IF NOT Y$="" THEN GO TO 1000 470 CLS 500 LET I = RND(10) 510 LET K=RND(3) 520 IF K = 1 THEN LET A(I) = 0 530 IF K = 2 THEN LET B(I) = 0 540 IF K = 3 THEN LET C(I) = 0 550 GO TO 200 1000 STOP When typing in a program like this where there are several similar lines the EDIT facility is very useful, because you can edit line numbers. For example; after entering line 210, type: EDIT RUBOUT 3 NEWLINE Statements 10 to 30 set up 3 arrays. A, B, and C of 10 elements each. Statements 100 to 140 set all the elements of all arrays to 1. 200 to 240 examine each element of the array A in turn. If an element is equal to 1 a • is printed. If an element is not 1 a space is printed. Similarly for 300 to 340 and 400 to 430. On the first pass all the elements are set to 1 and • is printed all the way through. 445 to 470 print the instruction and if the user then hits NEWLINE the screen is cleared. 500 to 540 select a random element of a random array to be set to 0. At 550 the program jumps back to print out all the arrays. The element which has been set to 0 is printed as a space - or nibble. As more nibbles are taken there is a greater chance that the element selected will already be 0 and thus the effective nibble rate slows down as the game progresses. ABS(n) this function gives n if n>0, and -n if n<0. n is any integer expression. e.g. ABS(5) = 5 ABS(-5) = 5 |