Ticker

6/recent/ticker-posts

Header Ads Widget

Responsive Advertisement

COMMANDS AND STATEMENTS IN GW-BASIC




WHAT ARE COMMANDS

Commands are instructions that tell the computer to perform a specific action. The same command can be used in the same form with any program. Let’s learn about the function and syntax of some useful commands in GW-BASIC. Commands are always typed in capital letters.


Important Commands in GW-BASIC


The CLS command

The CLS command is used for clearing the screen.

Syntax: CLS


The LIST command

The LIST command displays the whole program, or part of the program, that the computer is currently running. This is useful because it enables us to have a look at the program to spot any errors. We can also press the F1 key to run the LIST command.

Syntax: LIST (to list all the lines in the program)

LIST -15 (to list lines 1-15 only)

LIST 10-15 (to list lines 10-15 of the program)


The LOAD command

The LOAD command is used to transfer a program from a secondary storage medium to primary storage. The computer has to close all running programs before loading a new program. Once the program has been loaded, it can be executed. This means that the computer can start reading the program and follow its instructions. Adding [,R] allows the program to be executed as soon as it is loaded.

Syntax: LOAD “<filename>”


The SAVE command

The SAVE command is used to save a program. It is important to specify the name of the program. If the storage device already stores another file by same name, the computer will replace the old file with the program file.

Syntax: SAVE “<filename>”


The RUN command

The RUN command is used to execute a program. We can either run a command from the very beginning, or from a specific line. Again, the computer closes all open files before running a new program.

Syntax: RUN <line number> (to run a program from a specific line number)

   RUN “<filename>” (to run a program from the very beginning)

We can add [,R] after the file name so that the computer runs the new program without closing the open programs. The syntax changes.

Syntax: RUN <line number> [,R] (to run a program from a specific line number)

    RUN “<filename>” [,R] (to run a program from the beginning)


WHAT ARE STATEMENTS

Statements are instructions that tell the computer to perform an action that is unique to the program being run. Each statement has the same syntax, but it is included within the program. Almost every line of instructions in a program begins with a statement. Let’s learn about the function and syntax of some useful statements in GW-BASIC.


Statements in GW-BASIC


The REM statement

The REM statement is used to insert a remark or comment in a program. It is usually the first line of a program. The REM statement is not executed by the computer.

Syntax: REM <remark>


The INPUT statement

Sometimes we need to give input to the computer while it is executing a related program. This might happen when a cashier at a department store POS enters the price of each product one at a time. After each input, the computer follows the program to compute the total.

We can use the INPUT statement to program the computer so that it asks us for the next input. The computer can do this by displaying a question mark on the screen after it has computed the total for, say, the first three times. We can then insert the price of the fourth item. After computing the total of four items, the computer again displays a question mark.

Syntax: INPUT “<prompt>”,<variable>

The prompt may be a question mark. We can also assign a text message such as A, X, N, and so on. The computer assigns to the variable the value of the input that we provide.


The PRINT statement

The PRINT statement tells the computer to display some data or the result of processing on the monitor.

Syntax: PRINT <expression>

The expression is the output that we want to display. The output may be a message as we have seen in the INPUT statement. In such a case it is important to place the expression within double quotation marks. 

PRINT “PLEASE ENTER DATA”

Such data is called string data because it contains letters or characters in addition to numbers. String data is always placed within double quotation marks.

We can also ask the computer to display the value of a variable without specifying the value. In this case, we do not need to use quotation marks. If we have specified the value of X as X=10, we can type, PRINT X

The computer will display 10 (the value of X) on the monitor, and not the letter X. We can also use a question mark instead of typing the word PRINT.

? “PLEASE ENTER DATA”

? X


The LOCATE statement

The LOCATE statement is used to move the cursor to any defined position on the screen. We need to specify the row number and column number. Once the cursor is at the specified location, we can give a PRINT statement to print data at the location.

Syntax: LOCATE <row>, <column>


The LET statement

In the previous example, we saw that we had assigned a value of 10 to the variable X. We use the Let statement to assign a value to a variable.

Syntax: LET <variable>=<value>

   LET X=10

   LET A=2*5

However, it is not necessary to use the LET statement. We can simplify enter

   X=10

   A=2*5


The READ statement

The READ statement allows us to assign values to a number of variables. It is used together with the DATA statement.

Syntax: READ <variable>, <variable>


The DATA statement

The DATA statement is used together with the READ statement. It identifies the values of the variables specified in the READ statement.

Syntax: DATA <constant>, <constant>


The IF… THEN… ELSE statement

We learned how to use the IF… THEN… ELSE statement allows us to tell the computer what to do if the data meets a condition, and what to do if it does not meet the condition. In other words, if the condition is true for the given data, the THEN clause is executed, and after that the next statement is executed. If the condition is false for the given data, the computer ignores the THEN clause and executes the ELSE statement.

Syntax: IF <expression>, THEN <statement>, ELSE<statement>


The GOTO statement

The GOTO statement tells the computer to go to a specific line in the program. We can specify the line by its line number.

Syntax: GOTO <line number>


The END statement

The END statement tells the computer to go to a specific line in the program. We can specify the line by its line number.

Syntax: END


So we understand from the above text that command and the statements are very different. Many people think that they are the same but, we learned that a command is an instruction to computer to perform specific task. And the Statement is an instruction that tells the computer to perform a unique and a task which is not part of the program and is unnecessary. 




Post a Comment

0 Comments