For And Next; Rem - AMSTRAD cpc 6128 User Instruction

Integrated computer/disc system
Hide thumbs Also See for cpc 6128:
Table of Contents

Advertisement

Likewise, if END wasn't there in line 70, the program would continue to run, and
carry out line 80. The colon : before the word END separates it from the previous
instruction. Colons : can be used to separate two or more instructions -on one
program line. We have also added line 5 to clear the screen at the start of the
program. We will do this from now on in the following programs to make things look
neater.
Reset the computer by pressing [CONTROL] [SHIFT] and [ESC] keys.
FOR
and
NEXT
The FOR and NE X
T
commands are used when you want to carry out a specified
operation a number of times. The instructions for the specified operation must be
enclosed by the FOR N EX
T
loop.
Type in:
5'
c
L
s [RETURN]
1 0 for a = 1 to 1 0
[RETURN]
20 pr i n t "
0
per a t ion nu m b er" ; a
[RETURN]
3 0 ne x
t
a
[RETURN]
run
[RETURN]
You will see that the operation in line 20 has been carried out 10 times, as
instruct~d
by the FOR command in line
10.
Note also that the value of the variable a is
increased by 1 each time.
The keyword S T E P may be used to inform the FOR N EX T command how much the
variable should be 'stepped' per operation. For example, change line 1 13 to:
1 0 for a = 1 0 to 50s t e p 5
[RETURN]
run
[RETURN]
Negative steps may also be used, for example:
1 0 for a = 1 00 to 0 s t e p -1 0
[RETURN]
run
[RETURN]
REM
REM is short for REMark. The instruction tells the computer to ignore anything that
follows it on the line. Hence you can use REMarks to inform you of, for example, the
title of a program, or the use of a variable, as follows:
10 REM Zap the invaders
[RETURN]
20 L=5 :REM number of Lives
[RETURN]
Chapter 1 Page 30
Foundation Course

Advertisement

Table of Contents
loading

Table of Contents