Let

From BR Wiki
Revision as of 03:15, 23 January 2013 by Laura (talk | contribs) (→‎Syntax)
Jump to navigation Jump to search

The Let (LE) Statement evaluates a numeric or string expression and optionally assigns the value of the expression to one or more variables. Four numeric assignment operators (+=, -=, *= and /=) are now supported for the LET statement. These operators can be used when adding, subtracting, multiplying, or dividing a variable and assigning the result to the same variable. Thus, a statement previously coded as LET NUM_Days=NUM_Days+6 can now be coded as:

LET NUM_Days+=6

Besides offering substantial savings in code size and execution time, this feature helps prevent the typing errors that can occur with the use of longer variable names.

Comments and Examples

The main use of the LET statement is assignment. The result of an arithmetic calculation may be assigned to a single variable, as in the following example:

00770 LET AREA=PI*RADIUS**2
00780 TOTAL=(N+1)*N/2

NOTICE from line 780 that the LET keyword is optional. The LET statement can also be used to assign a single value to several variables at once, as in the following example:

00790 LET SUMA=SUMB=SUMC=SUMD=0

Another variation of the LET statement invokes a function without assigning any values to any variables:

00800 FNSCRNH (LINES)

Functions that do not return values generally perform other operations, such as displaying lines to the screen.

Syntax

Defaults

1.) No assignment (useful for invoking functions).
2.) Interrupt the program if an error occurs and "ON error" is not active.

Parameters

"Num-var=" and "string-var=" are optional parameters which represent numeric or string variables. These variables may be either subscripted or unsubscripted. They may also be repeated; this allows you to assign the same value to more than one variable in a single statement.

"Num-expr" and "string-expr" are required parameters that represent expressions to be evaluated to a single value. This is the value that will be assigned to the num- var or string-var variables described above. In general, expressions allow variables or functions (or operands) to be combined by one or more operators (e.g.: +, -, *, /, **, &, substring).

LET provides error processing with the optional "error-cond line-ref" parameter. See the Error Conditions chapter for more information.

Technical Considerations

1.) Relevant error conditions are: [[CONV, ERROR, EXIT, OFLOW, SOFLOW, and ZDIV.
2.) The keyword LET is optional when entering LET statements. Business Rules! automatically insert the keyword in program listings.
3.) The LET statement may be used to assign substring references. For example, the following results in A$ containing "AXYZD"
00200 A$ = "ABCD"
00210 B$ = "XYZ"
00220 A$(2:3) = B$



Automated Insertion

"let" is automatically inserted in most situations, however a few require typing the word. For example:

if x=1 then fn_do_something

will not work, because it requires a "let" as shown here:

if x=1 then let fn_do_something

Usually let is optional, few statements require its use, but BR! almost always automatically adds it when it's appropriate.

See Also