For To Next; Simple Arithmetic - AMSTRAD CPC464 User Manual

Cpc464 colour personal computer 64k
Hide thumbs Also See for CPC464:
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
enable you to put 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.
Other keywords associated with IF and THEN include ELSE, OR and GOTO. The use of these words
in the IF command will become clearer as you work through this guide.
Reset the computer by pressing [CTRL] [SHIFT] and [ESC] keys.

FOR TO NEXT

We will now show the use of the FOR, TO and NEXT commands. For this example we will show a
way the computer can print the 12 times table (1x12,2x12,3x12, etc) Type the following, note that the
* symbol means multiply.
5 c l s [ E N T E R ]
1 0 f o r a = 1 t o 2 0 [ E N T E R ]
2 0 p r i n t a " * 1 2 = " a * 1 2 [ E N T E R ]
3 0 n e x t a [ E N T E R ]
r u n [ E N T E R ]
You will notice the columns look untidy, so type in:
5 c l s [ E N T E R ]
1 0 f o r a = 1 t o 9 [ E N T E R ]
2 0 p r i n t a " * 1 2 = " a * 1 2 [ E N T E R ]
3 0 n e x t a [ E N T E R ]
4 0 f o r a = 1 0 t o 2 0 [ E N T E R ]
5 0 p r i n t a " * 1 2 = " a * 1 2 [ E N T E R ]
6 0 n e x t a [ E N T E R ]
r u n [ E N T E R ]
Try this program for multiplication tables using other numbers. For example, if you wanted to see
the 17 times table, replace the number 12 in lines 20 and 50 with the number 17. Finally, reset the
computer using the [CTRL][SHIFT] and [ESC] keys. Note that it is possible to specify the value of
each step taken in the FOR TO NEXT command by use of the STEP command. For further
information, study the description of FOR in Chapter 8.

SIMPLE ARITHMETIC

Your CPC464 can be used as a calculator quite easily.
To understand this carry out the following examples. We will use the ? symbol instead of typing print
in this section. The answer will be printed as soon as the
key is pressed.
[ENTER]

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents