Programming (or indirect) mode


Entering a command

Well, finally. All those lessens in preparation for a lesson on programming. After all, that is what we are here for in the first place.
We already know from the last lesson how to execute a line of code using the direct mode. If we want to write a program, its only necessary to store those lines of code, put a line number in front of each line and run the entire series of lines sequentially, by line number. This is a program, by definition. A group of lines of commands that can be interpreted and executed sequentially. This lesson shows us how to create a program, store it into the "Program Buffer" and RUN the program.


Remember the one liner that printed the numbers from one to ten?
CLS: FOR N= 1 TO 10: PRINT N: NEXT N
don't forget the ENTER key at the end of the command line....

Well its not necessary to type in the command line each time we wish to run that one liner. Simply put a line number in front of the line of code and press ENTER.
10 CLS: FOR N= 1 TO 10: PRINT N: NEXT N

Nothing spectacular happened. What did happen is that the interpreter recognized the line of code as a program step because is began with a number. The program, consisting of one line is stored in a memory location call a BUFFER. It remains there until it is needed. If you wish to review your program, type in the LIST command in the immediate mode.
LIST

When the interpreter sees the ENTER key closure, it will perform the LIST instruction and PRINT the program to the monitor.
When you wish to RUN the program, simply type in the RUN instruction.
RUN

If you wish to erase the program from the Program Buffer, use the NEW instruction.
NEW

It will delete the current program that is currently in the buffer and prepare the buffer for another program to be entered.

Mission accomplished for this lesson. There are some more program examples below for those that wish to play around with them. A new programmer may wish to see some more program examples.


Some Program examples for the beginner


Don't forget to use NEW in the immediate mode to clear the previous program.
type in the LIST instruction to make sure the program is properly loaded.
type in the RUN instruction when you wish to execute the program.

10 CLS
20 FOR N= 1 TO 10
30 PRINT N
40 NEXT N
50 PRINT " were done counting to ten"

10 CLS
20 FOR N= 1 TO 10
30 PRINT CHR$(7)
40 NEXT N
50 PRINT " CHR$(7) is the ascii character for the bell "

10 CLS: KEY OFF
20 PRINT
40 PRINT " Y= f(X)= X squared"
45 PRINT "********************"
50 PRINT " X", " Y"
60 FOR X= 1 TO 7
70 PRINT X,X*X
80 NEXT X
90 PRINT "********************"


Here is a time saver for programming with GWBasic


Some of us are lazy. We don't want to type in all the programs into the program buffer. That is why the Windows console mode has the copy and paste function built into it. The program examples may be copied from this lesson and pasted directly into the GWBasic window, rather requiring it to be type into the program buffer. These are the steps to do this.

Copy the program from this lesson by highlighting the text to be copied and using either a contrl C or the COPY function of the drop down function under the EDIT menu. This will put the program text into the clipboard viewer.

Open GWBasic with a double click and click on the console monitor to establish the destination for the contents of the clipboard .

Click on the PASTE button located on the task bar above the monitor to copy the contents of the clipboard into the GWBasic monitor. The entire program should appear and the cursor will be at the end of the code, just as if it had been typed in by hand from the keyboard. (br>
Press the ENTER key to enter this program into the GWBasic's program buffer. The cursor drop down to the left hand side of the next line.

Type in the LIST instruction to see that the program indeed got copied into the program buffer if you wish. Don't forget to use the NEW instruction to clear the program buffer before pasting in the new program.

Wouldn't it be nice if we could do this kind of thing with all our programs? Well... there is, and it will be coverec in another lesson about the LOAD and SAVE instruction. It is just another handy way to transfer text data from one part of the computer to another. That is what computers do well..........