Capítulo 3
GW-BASIC de repaso y practicante

Las sesiones de la práctica en este capítulo le ayudarán a repasar lo que usted ha aprendido. Si usted no ha hecho así pues, esto es un buen rato de girar su computadora y de cargar al intérprete de GW-BASIC.

3.1 Ejemplo para el modo directo

Usted puede utilizar su computadora en el modo directo para realizar operaciones aritméticas fundamentales. GW-BASIC reconoce los símbolos siguientes como operadores aritméticos:

Operación Operador de GW-BASIC
Adición +
Substracción -
Multiplicación *
División /

¿Para incorporar un problema, responda al aviso aceptable con un signo de interrogación (?), seguido por la declaración del problema usted desea solucionar, y presiona la llave DE VUELTA. En GW-BASIC, el signo de interrogación se puede utilizar alternativamente con la IMPRESIÓN de la palabra clave. La respuesta entonces se exhibe.

Mecanografíe el siguiente y presione la llave DE VUELTA:

?2+2

GW-BASIC exhibirá la respuesta en su pantalla:

autorización?2+2 4

Para practicar otras operaciones aritméticas, substituya + muestra por el operador deseado.

La lengua de GW-BASIC no se restringe a las funciones aritméticas. Usted puede también incorporar funciones algebraicas y trigonométricas complejas. Los formatos para estas funciones se proporcionan en el capítulo 6, las "constantes, las variables, las expresiones y los operadores."

3.2 Ejemplos para el modo indirecto

La lengua de GW-BASIC se puede utilizar para las funciones con excepción de cálculos algebraicos simples. Usted puede crear un programa que realice una serie de operaciones y después exhiba la respuesta. Para comenzar a programar, usted crea líneas de las instrucciones llamadas las declaraciones. Recuerde que puede haber más de una declaración sobre una línea, y que cada línea es precedida por un número.

Por ejemplo, para crear la IMPRESIÓN 2+3 del comando como declaración, mecanografíe el siguiente:

10 impresión 2+3

Cuando usted presiona la llave DE VUELTA, el cursor cambia de puesto a la línea siguiente, pero nada sucede. Para hacer que la computadora realiza el cálculo, mecanografíe el siguiente y presione la llave DE VUELTA:

funcione

Su pantalla debe parecer esto:

La impresión 2+3 de la autorización 10 funciona la 
autorización 5

Usted acaba de escribir un programa en GW-BASIC.

La computadora reserva su cálculo hasta que está ordenada específicamente para continuar (con el comando del FUNCIONAMIENTO). Esto permite que usted incorpore más líneas de la instrucción. Cuando usted mecanografía el comando del FUNCIONAMIENTO, la computadora hace la adición y exhibe la respuesta.

El programa siguiente tiene dos líneas de instrucciones. Mecanografíelo en:

10 x=3 20 impresión 2+x

Ahora utilice el comando del FUNCIONAMIENTO de hacer que la computadora calcule la respuesta.

Su pantalla debe parecer esto:

La impresión x=3 20 2+x de la autorización 10 funciona 
la autorización 5

Las dos características que distinguen un programa de un cálculo son

  1. Las líneas numeradas
  2. El uso del comando del funcionamiento

Estas características dejaron la computadora saber que se han mecanografiado todas las declaraciones y el cómputo se puede realizar de comenzar a terminar. Es la enumeración de las líneas que primero señala la computadora que esto es un programa, no un cálculo, y que no debe hacer el cómputo real hasta que se incorpora el comando del FUNCIONAMIENTO.

Es decir los cálculos se hacen bajo modo directo. Los programas se escriben bajo modo indirecto.

Para exhibir el programa entero otra vez, mecanografíe el comando de la LISTA y presione la llave DE VUELTA:

lista

Su pantalla debe parecer esto:

La impresión x=3 20 2+x de la autorización 10 funciona 
muy bien 5 la IMPRESIÓN aceptable X=3 20 2+X de la lista 10 muy bien

Usted notará un cambio leve en el programa. Las letras minúsculas que usted incorporó se han convertido en letras mayúsculas. El comando de la LISTA realiza este cambio automáticamente.

3.3 Llaves De Funcionamiento

Las llaves de funcionamiento son las llaves que se han asignado a los comandos frecuente-usados. Las diez llaves de funcionamiento están situadas en el lado izquierdo de su teclado. Una guía a estas llaves y a sus comandos asignados aparece en el fondo de la pantalla de GW-BASIC. Para ahorrar tiempo y golpes de teclado, usted puede presionar una llave de funcionamiento en vez de mecanografiar un nombre del comando.

Por ejemplo, para enumerar su programa otra vez, usted no necesita mecanografiar el comando de la LISTA; usted puede utilizar la llave de funcionamiento le asigna, en lugar:

Su programa debe aparecer en la pantalla.

Para funcionar el programa, presione simplemente la llave F2, que se asigna al comando del FUNCIONAMIENTO.

Pues usted aprende más comandos, usted aprenderá cómo utilizar las llaves F3 con F10. El capítulo 4, "el editor de plena pantalla de GW-BASIC," contiene más información sobre las llaves usadas en GW-BASIC.

3.4 Corregir Líneas

Hay dos maneras básicas de cambiar líneas. Usted puede

Para suprimir una línea, mecanografíe simplemente la línea número y presione la llave DE VUELTA. Por ejemplo, si usted el tipo 12 y presiona la llave DE VUELTA, línea número 12 se suprime de su programa.

Para utilizar el comando del CORREGIR, mecanografíe el comando CORRIGEN, seguido por el número de la línea que usted desea cambiar. Por ejemplo, mecanografíe el siguiente, y presione la llave DE VUELTA:

corrija 10

Usted puede entonces utilizar las llaves siguientes para realizar corregir:

Llave Función
CURSOR PARA ARRIBA,
CURSOR ABAJO,
EL CURSOR SE FUE,
LA DERECHA DEL CURSOR
Mueve el cursor dentro de la declaración
TECLA DE RETROCESO Suprime el carácter a la izquierda del cursor
CANCELACIÓN (DEL) Suprime el carácter actual
RELLENO (INS) Le deja insertar caracteres a la izquierda del cursor.

Por ejemplo, para modificar la declaración (línea) 10 para leer x=4, utilice la llave de control de CURSOR-RIGHT para mover el cursor debajo de los 3, y después mecanografíe 4. El número 4 substituye el número 3 en la declaración.

Ahora presione la llave DE VUELTA, y entonces la llave F2.

Su pantalla exhibe el siguiente:

La Autorización 10 X=4 FUNCIONA La Autorización 6

3.5 Ahorrar Su Archivo Del Programa

Crear un programa es como crear un fichero de datos. El programa es un archivo que contiene instrucciones específicas, o declaraciones, para la computadora. Para utilizar el programa otra vez, usted debe ahorrarlo, apenas como usted un fichero de datos.

Para ahorrar un archivo en GW-BASIC, utilice el procedimiento siguiente:

  1. Presione la llave F4. La palabra EXCEPTO del comando " aparece en su pantalla.
  2. Mecanografíe un nombre para el programa, y presione la llave DE VUELTA. El archivo se ahorra bajo el nombre de usted especificó.

Para recordar un archivo ahorrado, utilice el procedimiento siguiente:

  1. Presione la llave F3. La CARGA de la carga del comando " aparece en su pantalla.
  2. Mecanografíe el nombre del archivo.
  3. Presione la VUELTA.

El archivo se carga en memoria, y alista para que le enumere, corrige, o funciona.

 

 

 

 

 

 

 

--------------

Chapter 3
Reviewing and Practicing GW-BASIC

The practice sessions in this chapter will help you review what you have learned. If you have not done so, this is a good time to turn on your computer and load the GW-BASIC Interpreter.

3.1 Example for the Direct Mode

You can use your computer in the direct mode to perform fundamental arithmetic operations. GW-BASIC recognizes the following symbols as arithmetic operators:

Operation GW-BASIC Operator
Addition +
Subtraction -
Multiplication *
Division /

To enter a problem, respond to the Ok prompt with a question mark (?), followed by the statement of the problem you want to solve, and press the RETURN key. In GW-BASIC, the question mark can be used interchangeably with the keyword PRINT. The answer is then displayed.

Type the following and press the RETURN key:

?2+2

GW-BASIC will display the answer on your screen:

?2+2
 4
Ok

To practice other arithmetic operations, replace the + sign with the desired operator.

The GW-BASIC language is not restricted to arithmetic functions. You can also enter complex algebraic and trigonometric functions. The formats for these functions are provided in Chapter 6, "Constants, Variables, Expressions and Operators."

3.2 Examples for the Indirect Mode

The GW-BASIC language can be used for functions other than simple algebraic calculations. You can create a program that performs a series of operations and then displays the answer. To begin programming, you create lines of instructions called statements. Remember that there can be more than one statement on a line, and that each line is preceded by a number.

For example, to create the command PRINT 2+3 as a statement, type the following:

10 print 2+3

When you press the RETURN key, the cursor shifts to the next line, but nothing else happens. To make the computer perform the calculation, type the following and press the RETURN key:

run

Your screen should look like this:

Ok
10 print 2+3
run
 5
Ok

You have just written a program in GW-BASIC.

The computer reserves its calculation until specifically commanded to continue (with the RUN command). This allows you to enter more lines of instruction. When you type the RUN command, the computer does the addition and displays the answer.

The following program has two lines of instructions. Type it in:

10 x=3
20 print 2+x

Now use the RUN command to have the computer calculate the answer.

Your screen should look like this:

Ok
10 x=3
20 print 2+x
run
 5
Ok

The two features that distinguish a program from a calculation are

  1. The numbered lines
  2. The use of the run command

These features let the computer know that all the statements have been typed and the computation can be carried out from beginning to end. It is the numbering of the lines that first signals the computer that this is a program, not a calculation, and that it must not do the actual computation until the RUN command is entered.

In other words, calculations are done under the direct mode. Programs are written under the indirect mode.

To display the entire program again, type the LIST command and press the RETURN key:

list

Your screen should look like this:

Ok
10 x=3
20 print 2+x
run
Ok
 5
Ok
list
10 X=3
20 PRINT 2+X
Ok

You'll notice a slight change in the program. The lowercase letters you entered have been converted into uppercase letters. The LIST command makes this change automatically.

3.3 Function Keys

Function keys are keys that have been assigned to frequently-used commands. The ten function keys are located on the left side of your keyboard. A guide to these keys and their assigned commands appears on the bottom of the GW-BASIC screen. To save time and keystrokes, you can press a function key instead of typing a command name.

For example, to list your program again, you needn't type the LIST command; you can use the function key assign to it, instead:

Your program should appear on the screen.

To run the program, simply press the F2 key, which is assigned to the RUN command.

As you learn more commands, you'll learn how to use keys F3 through F10. Chapter 4, "The GW-BASIC Screen Editor," contains more information about keys used in GW-BASIC.

3.4 Editing Lines

There are two basic ways to change lines. You can

To delete a line, simply type the line number and press the RETURN key. For example, if you type 12 and press the RETURN key, line number 12 is deleted from your program.

To use the EDIT command, type the command EDIT, followed by the number of the line you want to change. For example, type the following, and press the RETURN key:

edit 10

You can then use the following keys to perform editing:

Key Function
CURSOR UP,
CURSOR DOWN,
CURSOR LEFT,
CURSOR RIGHT
Moves the cursor within the statement
BACKSPACE Deletes the character to the left of the cursor
DELETE (DEL) Deletes the current character
INSERT (INS) Lets you insert characters to the left of the cursor.

For example, to modify statement (line) 10 to read x=4, use the CURSOR-RIGHT control key to move the cursor under the 3, and then type a 4. The number 4 replaces the number 3 in the statement.

Now press the RETURN key, and then the F2 key.

Your screen displays the following:

Ok
10 X=4
RUN
 6
Ok

3.5 Saving Your Program File

Creating a program is like creating a data file. The program is a file that contains specific instructions, or statements, for the computer. In order to use the program again, you must save it, just as you would a data file.

To save a file in GW-BASIC, use the following procedure:

  1. Press the F4 key. The command word SAVE" appears on your screen.
  2. Type a name for the program, and press the RETURN key. The file is saved under the name you specified.

To recall a saved file, use the following procedure:

  1. Press the F3 key. The command load LOAD" appears on your screen.
  2. Type the name of the file.
  3. Press RETURN.

The file is loaded into memory, and ready for you to list, edit, or run.

1