Quantcast LET Statement

Custom Search
LET Statement

One of the more useful BASIC language keywords is LET. It is an instruc-tion to the computer to either assign a specified value to a variable name, or to do certain computations and then assign the result to a variable name. The LET statement is not a statement of algebraic equality; rather, it is a definition that assigns a value or a number to a variable. 

 The LET statement can be used to assign a constant value to a variable name, a variable to a variable name, or the result of an expression to a variable name. Therefore, the LET statement is often referred to as an statement.

For example:

Assigning a constant value to a variable name

In this example the value 212 is assigned to the variable name A and stored in memory with the location name, A. The equal sign should be read as be replaced by or more precisely be assigned the value of. This does not represent algebraic equality.

Letís examine a program with a LET statement that assigns a constant value to a variable name. Assume we wanted to find the area of three circles, each with a radius of 5, 6, and 7 inches respectively. We know that pi (3. 1416)  will be used in each computation; therefore, if we assign the constant value of 3.1416 to a variable name (P), we can use the variable name in each computation rather than writing 3.1416 three times. This eliminates repetitive coding. The program could be written this way:


Assigning a constant value to a variable name

If a value is to be used several times in a program, it can be assigned to a variable name and stored in the computerís memory. When that value is to be used, you can reference it by using the variable name. In the previous example that is what we did, we assigned 3.1416 the variable name of P and each time we wanted to use it, we referenced P rather than write 3.1416 each time.

Since an expression is really nothing more than a value represented by algebraic symbols, the LET statement can also be used to assign a variable name the value of an expression as in a formula or equation. Using the previous example of the circles, letís see how this works.


Assigning the value of an expression to a variable name 

In this example, the expressions on the right side of the equal sign were calculated and the results assigned to the variable names Al, A2, and A3. Then in line 50 when we wanted to print the answers we referenced the variable names instead of having to recode the expressions.

Three important points to remember about the LET statement are: 

    It assigns a value to a variable name.

    The value may be expressed as a constant, another variable or an expression.

    The value is stored in memory and may be referenced by its variable name.


Privacy Statement - Copyright Information. - Contact Us

Integrated Publishing, Inc.