Personal Computer News


Array Amendments On The Memotech

 
Published in Personal Computer News #076

Array Amendments on the Memotech

It's sometimes necessary to examine or change an array of variables when a program is already running and contains data in the form of variables. One method is to temporarily add lines to the program. Thus, to increase all items in A(N) with a value of more than 35 by 1 type:

9000 FOR N=1 TO 40
9010 IF A(N)>35 THEN LET A(N)=A(N)+1
9020 NEXT

Unfortunately, the Memotech MTX 512, like most other machines, does not allow addition of program lines without automatically clearing all variables. A direct command does not have this unfortunate consequence. However, even with multi-statement lines, you cannot enter:

FOR N=1 TO 40:IF A(N)>35 THEN LET A(N)=A(N)+1:NEXT

as a single command and expect it to work, any more than as a single program line - for if the condition is false, the NEXT is ignored.

However, Boolean algebra provides a solution, -1 being the value the Memotech uses for "TRUE" and typing:

FOR N=1 TO 40:IF A(N)>35 THEN
   LET A(N)=(A(N)+):NEXT

achieves the desired result, as a direct command.

R. W. Sharples, Mill Hill, London NW7

R. W. Sharples