Custom Search
 
  

 
Numeric-variable Name

A numeric-variable name is an arbitrary name that you select, and you and the computer system use to refer to some location in memory. The value contained in that location may change or vary during execution of a program.

Example:

C = 5/9(F 32) is the formula for converting temperature in Fahrenheit to Celsius (centigrade). In this equation 5, 9, and 32 are all constants; that is, they never change. F is the variable name for temperature in Fahrenheit; its value varies as the temperature goes up and down. C is the variable name for the temperature in degrees Celsius; it refers to the location in memory where the solution to the computation is stored, and its value varies as the value of F varies according to the formula.

A numeric-variable name maybe any single letter of the English alphabet (A to Z), or a single letter followed by any single decimal digit (0 through 9). Table 3-1 shows examples of valid and invalid variable names.

Table 3-1.Numeric-variable Names

String-constants and String-variables

Not all constants and variables are numeric. They may be a series or string of characters such as name ("JOHN DOE") or address ("206 VILLAGE GREEN CIRCLE"). They may be composed of any combination of letters, digits, and special characters and are enclosed in quotation marks. Generally they are called character strings and may be either a string-constant or a string-variable. In BASIC, variable names for string-variables are any single letter (A-Z) followed by a dollar sign ($).

For example:

String-constant

String-variable

The important things to remember about constants and variables are:

Numeric-constants are whole or decimal numbers that do not change throughout a program.

Variables, referenced by variable names, may represent numeric values or character strings.

Variables are used when values may change during execution of a program.

Variable names for numeric values may be a single alphabetic character (A-Z), or one alphabetic character followed by a single numeric digit (0-9).

Variable names for character strings are a single alphabetic character

(A-Z) followed by a dollar sign ($).

String constants are character strings that do not change throughout a program.

SUMMARY

Simple problems can be solved with BASIC by using only two or three instructions. These are the END, PRINT and LET statements. To use these effectively, you must know how they work and what rules must be followed in using them.

The END statement, which must be the last statement in every BASIC program, has two functions. It indicates to the compiler that there are no more BASIC statements for it to translate and it terminates execution of the program.

The PRINT statement is used to instruct the computer to output something either on the terminal or the printer. The standard print line in BASIC is divided into print zones or fields of 16 spaces each.

The two punctuation marks used in PRINT statements are the comma and semicolon. A comma used as a separator in a PRINT statement causes standard spacing and a semicolon causes packed spacing.

Information enclosed in quotation marks in a PRINT statement will be printed exactly as it appears in the program.

The LET statement can be used to assign a constant value to a variable name, a variable to a variable name, or the results of an expression to a variable name. The equal sign in a LET statement does not indicate algebraic equality, rather it means be assigned the value of. The value assigned by a LET statement is stored in the computers memory; therefore, it can be referenced by its variable name.

Both the PRINT and LET statements may contain expressions with arithmetic operations. These arithmetic operations must be specified by the appropriate operation symbol. Should you forget to include the symbol, the computer will not insert it for you, but will give you an error message. Arithmetic operations within an expression are executed in a prescribed order of precedence: exponentiation first; multiplication and division next; and addition and subtraction last. Parentheses are used to alter the normal order of precedence. Operations inside parentheses are performed first. If there are parentheses inside parentheses, the operations inside the inner pair are performed first.

Constants and variables are used to refer to numeric values or character strings. A constant is a whole or decimal number or character string whose value does not change. A variable name is an arbitrary name you select and you and the computer use to refer to a value stored in the computers memory. This value may vary during execution of the program, but can contain only one value at a time.







Western Governors University
 


Privacy Statement - Copyright Information. - Contact Us

Integrated Publishing, Inc. - A (SDVOSB) Service Disabled Veteran Owned Small Business