Sinclair ZX81 User Manual page 38

Hide thumbs Also See for ZX81:
Table of Contents

Advertisement

(Actually we have cheated slightly here: it should really be GOTO 21 instead of GOTO 30. This will have
the same effect in our program.)
3. Run the program, & then type
PRINT C
Why is the answer 6, & not 5?
[Answer: the NEXT statement in line 60 is executed 5 times, and each time 1 is added to C.] What
happens if you put STEP 2 in line 20?
4. Change the third program so that instead of automatically adding five numbers, it asks you to input how
many numbers you want adding. When you run this program, what happens if you input 0, meaning that
you want no numbers adding? Why might you expect this to cause problems to the computer, even though
it is clear what you mean? (The computer has to make a search for the statement NEXT C, which is not
usually necessary.) In fact this has all been taken care of.
5. Try this program, to print out the numbers from 1 to 10 in reverse order.
10 FOR N=10 TO 1 STEP -1
20 PRINT N
30 NEXT N
Convert this into a program that does not use FOR-NEXT loops in the same way that you would convert
program 3 into program 2 (see exercise 2). Why does the negative step make is slightly different?

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents