Tweet |
Custom Search
|
|
Assigning Statement Numbers Duplicate statement numbers are not allowed. If two statements are entered with the same statement number, the computer will accept the second state-ment with the duplicate statement number and replace the first.When assigning statement numbers, it is a good idea to increment them by 10; this will allow you to insert additional statements between existing statements in your program later. This is not mandatory, but it is a good practice. This technique will prevent you from having to completely renumber a program, if you find you need to add a statement after you have completed writing your program. The following example shows how this technique works:In this example the PRINT statement, which is needed to print the results from your calculations was omitted. Since the line numbers were incremented by 10, it was easy to assign the PRINT statement a line number between 60 and 70.When the program is run or you list your program, the PRINT statement, line number 65, will be inserted in its proper place by the computer.Spacing Within Statements Spacing within statements in your program is not very important, the com-puter generally ignores spaces except those within quotation marks. For example, one of the sample programs used earlier could be written this way:OR: or various other ways. However, as a matter of practice, you will want to use spacing that provides clarity and maintains the integrity of the statement. Appropriate use of spaces within a line will make the line easier for you and others to read and understand.The sample program below is an example of the recommended spacing within statements:10 REMARK THIS PROGRAM CONVERTS INCHES TO CENTIMETERS 20 INPUT 1 30 LET C = 1*2.54 40 PRINT "INCHES","CENTIMETERS" 50 PRINT I,C 60 END In this example, we have used spacing techniques similar to those you would use in ordinary typing.KEYING IN A PROGRAM Once you have written a program and have a computer available, you are ready to key in your BASIC program. The procedures for this will vary, depending upon the computer system you are using. Consult your users manual for procedures for your specific computer.Keying Statements To enter BASIC statements, you key in the statement beginning with the statement (line) number, after the prompt on the terminal. Once you have completed the statement, depress the RETURN key. Only one statement may be entered per line. Some computers are equipped with an automatic line numbering feature which will automatically number your statements, incrementing them by 10.It is not necessary to key in your BASIC statements in sequence by line number. The computer will sort the statements by line number and place them in ascending sequence, regardless of the sequence in which you keyed them in. The following example shows what we mean: You forgot to type in line 50 when you initially entered your program, but that is not a catastrophe. You can enter it after line 60. By entering the system command LIST, you will find line 50 has been placed in the proper sequence in the program. Your listing will look like this: |
||