AMSTRAD CPC464 User Manual page 62

Cpc464 colour personal computer 64k
Hide thumbs Also See for CPC464:
Table of Contents

Advertisement

Simply by using N in this way, we have told the computer that N is a variable. The definition of the
FOR statement in BASIC requires that it should be followed by a variable - so the computer assumes
that whatever follows FOR is just that.
We have also told the computer that N = 32 t o 255.. Thus we have declared the range of the
variable, it is in effect a sequence starting at 32, and finishing at 255.
Having declared this variable, we should then instruct the computer what it should sdo with it - the
next line does just this:
2 0 P R I N T C H R $ ( N ) ;
It tells the computer that it should convert this number value that has been assigned to N into the
character of the corresponding number, the CHR$(N) function is the BASIC instruction that
performs this task. And having looked into its memory to see what character corresponds to the
value of N, the computer prints it on the screen.
The semicolon at the line end instructs the computer to prevent the carriage return and line feed (set
the next character to print back to the left hand column, and drop down to a new line) that otherwise
would automatically occur, causing the character set to list down the leftmost column of the screen,
rather than one character after another in rows.
The next line tells the computer that when it has performed the task with the first number in the
sequence (32), it should return to the line where the FOR is located, and do the same again with the
NEXT value it assigns (allocates) to the variable N. This process is known as looping, and this is one
of the most vital and fundamental aspects of computer programming and operation.
This FOR loop is one of the most fundamental features of computing, it occurs in all programming
lanuages in one shape or form. It saves typing in long repetitious sequences manually, and you will
quickly come to use it in your own programming.
When this FOR loop reaches the limit of its declared range (2551, the opeiation ceases and the
computer then looks for the next line after line 30 - but there isn' t one, so it simply stops and returns
to the command prompt by displaying Ready. This tells you that the computer is ready to accept
further instructions - or you can RUN again and repeat the execution of the program. The program is
safely stored away in the memory and will remain there until you tell the computer otherwise – or if
you turn the power off - when all data (programs, variables etc) will be lost unless you save it using
the cassette.
This program neatly illustrates a fundamental point about computing - that is everything the
computer does is related to numbers. The computer has displayed the alphabet - and a whole range
of other characters - using a number as its reference to the character required. When you type the
key marked A, you don' t ask the computer to type an A on the screen, but you tell the computer to
look into the part of its memory that contains the numeric information to display a letter A on the
screen. The actual location of this data is defined by the numeric code that is activated by the action
of typing at the keyboard.
Each character has a corresponding number, and these are listed in Appendix III of this manual.

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents