![](/images/new-backgrounds/1032235/32235457x1.webp)
If more values are read than there are numbers in the DATA statements, an out of data (OD) error occurs. That is why in line 40 we check to see if
Before going back to line 10 for another guess, we need to make the READ's begin with the first piece of data again. This is the function of the "RESTORE." After the RESTORE is encountered, the next piece of data read will be the first number in the first DATA statement again.
DATA | statements may be | placed anywhere within the program. Only READ statements make use |
of the DATA statements | in a program, and any other time they are encountered during program | |
execution they will be | ignored. | |
212 | STRINGS |
|
A list of characters is referred to as a "String." Rockwell, R6500, and THIS IS A TEST are all strings. Like numeric variables, string variables can be assigned specific values. String variables are
distinguished from numeric variables by a "$" after the variable name.
For example, try the following:
A$="ROCKWELL R6500"
PRINT A$
ROCKWELL R6500
In this example, we set the string variable A$ to the string value "ROCKWELL R6500." Note that we also enclosed the character string so be assigned to A$ in quotes.
LEN FUNCTION
Now that we have set A$ to a string value, we can find out what the length of this value is (the number of characters it contains). We do this as follows:
PRINT LEN(A$),LEN("MICROCOMPUTER")
14 13
The "LEN" function returns an integer equal to the number of characters in a string.
A string expression may contain from 0 to 255 characters. A string containing 0 characters is called the "null" string. Before a string variable is set to a value in the program, it is initialized to the null
string. Printing a null string on the terminal will cause no characters to be printed, and the printer or cursor will not be advanced to the next column. Try the following:
PRINT LEN(Q$);Q$;3 0 3
Another way to create the null string is: Q$=""
Setting a string variable to the null string can be used to free up the string space used by a
LEFT$ FUNCTION
It is often desirable to access parts of a string and manipulate them. Now that we have set A$ to "ROCKWELL R6500," we might want to print out only the first eight characters of A$. We would
do so like this:
PRINT LEFT$(A$,8)
ROCKWELL
"LEFT$" is a string function which returns a string composed of the leftmost N characters of its string argument. Here is another example:
FOR N=1 TO LEN(A$):PRINT LEFT$(A$,N):NEXT N
R
RO