Let: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
(Created page with "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 ...")
 
 
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
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 [[Operations|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:
The '''Let''' (LE) [[Statement]] evaluates a numeric or string expression and optionally assigns the value of the expression to one or more variables.


LET NUM_Days+=6
LET is also used when calling functions. When LET is used this way, imagine that you're assigning the results of the function to a variable but the variable part is optional.


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.  
In BR, the LET statement is typed for you almost any time its required. So its usually not necessary to actually write LET in your programs.


=== Comments and Examples ===
=== Comments and Examples ===
Line 21: Line 21:


Functions that do not return values generally perform other operations, such as displaying lines to the screen.  
Functions that do not return values generally perform other operations, such as displaying lines to the screen.  
If the function is in a library, its the LET statement that loads the library function into present memory and runs it. In the following example, the Fntotalsales is called from the program (aka library) Sales1. Line 510 will provide the outcome of the function for the current program.
00500    library "sales1" : Fntotalsales
00510    let Totalsales=Fntotalsales(Sales,Comrate,.0825,Tax,Commission)
See [[Library Facility]] for more information.
In addition, four numeric assignment [[Operations|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.


=== Syntax ===
=== Syntax ===
 
LET {{<[[numeric variable]]>=|<[[string variable]]>=}[,...] {<[[numeric expression]]>|<[[string expression]]>}|<[[function]]>|<[[library function]]>} [<[[error condition]]> <[[line ref]]>][,...]
[[Image:HELP0092.jpg]]<br>
[[Image:Let.png|600px]]


=== Defaults ===
=== Defaults ===
Line 37: Line 54:
"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.: +, -, *, /, **, &amp;, substring).  
"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.: +, -, *, /, **, &amp;, substring).  


LET provides error processing with the optional "error-cond line-ref" parameter. See the Error Conditions chapter for more information.  
"Library function" names a function within a library that has already been identified.
 
"Function" can be any function.
 
LET provides error processing with the optional "error-cond line-ref" parameter. See [[Error Conditions]] for more information.


=== Technical Considerations ===
=== Technical Considerations ===


:1.) Relevant error conditions are: [[CONV, [[ERROR]], [[EXIT]], [[OFLOW]], [[SOFLOW]], and [[ZDIV]].  
: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.  
:2.) The keyword LET is optional when entering LET statements. [[Business Rules!]] automatically inserts 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"
:3.) The LET statement may be used to assign substring references. For example, the following results in A$ containing "AXYZD"


Line 49: Line 70:
  00220 A$(2:3) = B$
  00220 A$(2:3) = B$


<br>  
<br>
 
=== Automated Insertion ===
 
In BR, the LET statement is typed for you almost any time its required. So its usually not necessary to actually write LET in your programs.
 
If you're using an external editor, the word LET will be added as the program is compiled, and if you're using the built in BR console to write your programs, its added for you as you press ENTER to save each line.
 
So feel free to write your programs like this:
 
00500 X=500
00520 Y=X+20
00540 Z=fnCalculateCircumference(Y)
00550 fnPrintCircumference(Z)


<br>
and BR will turn it into this for you:


=== Automated Insertion ===
00500 let X=500
00520 let Y=X+20
00540 let Z=fnCalculateCircumference(Y)
00550 let fnPrintCircumference(Z)


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


  if x=1 then fn_do_something
  if x=1 then fn_do_something ! Incorrect


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


  if x=1 then let fn_do_something
  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.
Usually let is optional, few statements require its use, but BR! almost always automatically adds it when it's appropriate. See exceptions below.
 
====Exceptions====
 
Following the keywords [[then]] or [[else]] each of these keywords require a preceding "Let"
* fn... (any [[User Defined Functions]] call)
* [[curfld]]
* [[fkey]]
* [[help$]]
* [[menu]]
* [[msgbox]]
* [[setenv]]
* [[sleep]]
* [[str2mat]]


=== See Also ===
=== See Also ===
Line 69: Line 119:
*[[Append]]  
*[[Append]]  
*[[Operators]]
*[[Operators]]
*[[Library Facility]]


<br> <noinclude>
<br> <noinclude>

Latest revision as of 14:28, 5 October 2017

The Let (LE) Statement evaluates a numeric or string expression and optionally assigns the value of the expression to one or more variables.

LET is also used when calling functions. When LET is used this way, imagine that you're assigning the results of the function to a variable but the variable part is optional.

In BR, the LET statement is typed for you almost any time its required. So its usually not necessary to actually write LET in your programs.

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.


If the function is in a library, its the LET statement that loads the library function into present memory and runs it. In the following example, the Fntotalsales is called from the program (aka library) Sales1. Line 510 will provide the outcome of the function for the current program.

00500    library "sales1" : Fntotalsales
00510    let Totalsales=Fntotalsales(Sales,Comrate,.0825,Tax,Commission)

See Library Facility for more information.

In addition, 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.


Syntax

LET {{<numeric variable>=|<string variable>=}[,...] {<numeric expression>|<string expression>}|<function>|<library function>} [<error condition> <line ref>][,...]

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).

"Library function" names a function within a library that has already been identified.

"Function" can be any function.

LET provides error processing with the optional "error-cond line-ref" parameter. See Error Conditions 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 inserts 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

In BR, the LET statement is typed for you almost any time its required. So its usually not necessary to actually write LET in your programs.

If you're using an external editor, the word LET will be added as the program is compiled, and if you're using the built in BR console to write your programs, its added for you as you press ENTER to save each line.

So feel free to write your programs like this:

00500 X=500
00520 Y=X+20
00540 Z=fnCalculateCircumference(Y)
00550 fnPrintCircumference(Z)

and BR will turn it into this for you:

00500 let X=500
00520 let Y=X+20
00540 let Z=fnCalculateCircumference(Y)
00550 let fnPrintCircumference(Z)

However a few situations require typing the word, as in the following example:

if x=1 then fn_do_something ! Incorrect

This line 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 exceptions below.

Exceptions

Following the keywords then or else each of these keywords require a preceding "Let"

See Also