For instance, with commas, replace the 30 by
30
PRINT
A,
& run the program to see how successive
PRINT
statements can print on the same line but spread out in
two columns.
With semicolons, on the other hand, with
30
PRINT
A;
everything is jammed together.
Try also
30
PRINT
A
Now type in these extra lines.
100
REM
THIS PROGRAM MEASURES STRINGS
110
INPUT
A$
120
PRINT
A$,LEN A$
130
GOTO
110
This is a sepearate program from the last one, but you can keep them both in at the same time. To run
the new one, type
RUN
100
This program inputs a string instead of a number, & prints it & its length. Type
CAT (&
NEWLINE
, as usual)
Because the computer is expecting a string, it prints out two string quotes - this is a reminder to you, & it
usually saves you some typing as well. But you don't have to restrict yourself to string constants (explicit
string with opening & closing quotes & all their characters in between); the computer will evaluate any
string expression, such as one with string variables. In this case you might have to rub out the quotes that
the computer has displayed. Try this. Rub them out (with &
RUBOUT
twice), & type
A$
Since A$ still has the value "CAT", the answer is CAT 3 again.
Now input
A$
again, but this time without rubbing out the string quotes. Now A$ has the value "A$", & the answer is 2.
If you want to use
STOP
for string input, you must first move the cursor back to the beginning of the line,
using .
Now look back at the
RUN
100 we had earlier on. That jumps to line 100, so couldn't we have said
GOTO
100 instead? In this case, it so happens that the answer is yes, byt there is a difference.
RUN
100
first of all clears the variables (like
CLEAR
in chapter 6), & after that works just like
GOTO
100.
GOTO
100
doesn't clear anything. There may well be occasions when you want to run a program without clearing any
variables. Here
GOTO
is necessary &
RUN
could be disastrous, so it is best to get into the habit of
automatically typing
RUN
to run a program.
Another difference is that you can type RUN without a line number, & it starts off at the first line in the
program.
GOTO
must always have a line
number.
Both these programs stopped because you typed
STOP
in the
INPUT
line; but sometimes - by mistake -
you write a program that you can't top & won't stop itself. Type