• Keine Ergebnisse gefunden

ERROR: MISSING ASSIGNMENT OPERATOR

Im Dokument Timeshared BASIC/2000, Level F (Seite 21-27)

The user may press return and re-enter the statement in the correct form. If the error is not obvious, type any character after the message followed by return. The system will respond with a diagnostic message:

30 PRING S

ERROR: MISSING ASSIGNMENT OPERATOR

Typing a colon causes the diagnostic message to be printed. Any other character could have been typed with the same result.

Changing or Deleting a Statement

If an error is made before return is pressed, the error can be corrected with the backspace character (+-) or the line may be cancelled with Xc. (See "Errors During Logging On", above.) After return

is pressed, the statement can be changed or deleted.

To change a statement, simply type the same statement number followed by the desired statement.

To change this statement:

30 PRINT X

Retype it as:

30 PRINT 5

A change of this type can be made any time before the program is run.

To delete a statement, type the statement number followed by a return:

30

Statement 30 is deleted.

The DELETE command described in Section III is useful to delet-e a group of statements.

BASIC

Programs

Any statement or group of statements that can be executed constitutes a program. The last state-ment (the statestate-ment with the highest statestate-ment number) of every program must be an END statement. The following is an example of a simple BASIC program:

15 F'P I

t-n

::::5+5

25 E t-i II

15 and 25 are statement numbers. PRINT is a key word or instruction that tells TSB the kind of action to perform. In this case, it prints the result of the expression that follows. 35+5 is an arithmetic expression. It is evaluated by the system, and when the program is run, the result is printed. END is also a key word. It informs TSB that this is the end of this program. An END statement is required as the last statement within every program.

Usually, a program contains several statements. The following four statements are a program:

10

INPUT

A~B~C~D~E

20 LET S=(A+B+C+D+E)/5

:30 PRHH S

40

Et·m

This program, which calculates the average of five numbers, is shown in the order of its execution.

It could be entered in any order if the statement numbers assigned to each statement were not changed. The following program executes exactly like the program above:

40

Et'm

20 LET S=(A+B+C+D+E)/5

10

INPUT

A~B~C~D~E

::::0

PPItH

:~:

Generally, it is a good idea to number statements in increments of 10. This allows room to insert additional statements as needed.

User's Work Area

When statements are entered at the terminal, these statements become part of the user's work area.

All statements in the user's work area constitute the current program.

Any statement in the user's work area can be edited or corrected; the resulting statement will then replace the previous version in the user's work area. When the user logs off the TSB system, the work area is cleared. Commands are available with which to retain the contents of the user's work area in the user's library.

Listing a Program

At any time while a program is being entered, the LIST command can be used to produce a listing of the statements that have been accepted by the TSB system. LIST causes the system to print a listing of the current program at the terminal.

After deleting or changing a line, LIST can be used to check that the deletion or correction has been made. For example, a correction is made while entering a program:

10 U~INPUT A~B~C~D~E

20

PP~~LET

S=(A+B+C+D+E)/5

::::0

PPItH

S 40

Et·m

To check the corrections, list the program:

LIST

10 INPUT

A~B~C~D~E

20 LET S=(A+B+C+D+E)/5

:~: 0

PP

I t'lT :~:

40 am

Should the statements be entered out of order, the LIST command will cause them to be printed in ascending order by statement number. For example, the program is entered in this order:

20 LET S=(A+B+C+D+E)/5

:~: 0 P P ItH ::;::

40 am

10 INPUT

A~B~C~D~E The list will be in correct order of. execution:

LIST

10 INPUT

A~B~C~D~E

20 LET S=(A+B+C+D+E)/5

:~: 0 PP I t'lT :~:

40 END

Running a Program

After the program is entered and, if desired, checked with LIST, it can be executed with the RUN command. RUN will be illustrated with two sample programs.

The first program has two statements:

15 PPItH 35+5 25 ErlD

When run, the result of the expression

35+5

is printed:

Because the program contains a PRINT statement, the result is printed when the program is run.

When execution of a program is complete the system prints the message DONE at the user's terminal.

The second sample program averages a group of five numbers. The numbers must be input by the user:

10 INPUT

A~B~C~D~E

20

LET S=(A+B+C+D+E)/5

:::: (I

PP ItH :::

40 Et·m

Each of the letters following the word INPUT and separated by commas names a variable that will contain a value input by the user from his terminal. When the program is run, TSB signals that input is expected by printing a question mark. The user enters the values following the question mark. They are entered with a comma between each successive value.

The statement LET S

=

(A+B+C+D+E)/5 assigns the value of the expression to the right of the equal sign to the variable S on the left of the equal sign. The expression first adds the variable values within parentheses and then divides them by 5. The result is the value of S.

When the program is run, the user enters input values and the computer prints the result:

Deleting a Program

If a program that has been entered.and run is no longer needed, it can be deleted from the user's work area with the SCRATCH command. SCRATCH deletes whatever program has been entered by the user during the current session.

The first program entered was:

15 PP ItH :35+5

25 E t-i II

This program should be scratched before entering the next program. Otherwise, statement numbers may overlap causing undesirable results. In the latter case, when RUN is typed, the program will execute in order of the statement numbers. The program will execute until the first END statement is encountered. For example, if the program above remains in the user's work area and the user enters a new program, as follows:

10 INPUT

A~B~C~D~E

20 LET S=(A+B+C+D+E)/5

:::: 0

PP

I t'lT :~:

4 (I Et'lD

Typing RUN produces the following results:

pun

The program executes statements 10 through 25, accepting input from the user but printing the result of the expression

35+5.

A listing of the current program would appear:

10 InpUT

A~B.C~D~E

15 PPItH J5+5

20 LET S=(A+B+C+D+E)/5

25 Et"iII

:~: (I P F: I

tH :::

40 Et·m

Documenting a Program

Remarks that explain or comment can be inserted in a program with the REM statement. Any remarks typed after the word REM will be printed in the program listing but will not affect pro-gram execution. As many REM statements can be entered as are needed.

The sample program to average five numbers can be documented with several remarks:

5 PEt'1 7 PH1 15 PH1 25 PEt'1

THIS PPOGRAM AVERAGES

Im Dokument Timeshared BASIC/2000, Level F (Seite 21-27)