Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎


Keyword Abbreviation Token (hex) Version(s) Classification
LET L{Shift+E} 88 1.0 to 7.0 Command and Statement

[ LET ] variableexpression
Parameters Type Legal Value(s) Default Value Note(s)
variable Float, Integer, or String
any non-reserved name
or TI$
same as (or convertable to)
the type of variable
0 ~ 255 chars (string)
-32768 ~ +32767 (integer)
±2.93873588e-39 ~ ±1.70141183e+38 (float)
A literal string must be quoted (")
Variable declaration and assignment.

LET is a completely optional keyword.  It is provided for compatibility with other BASICs, and it helps make clear that an assignment is being made (without LET, it appears to be an algebraic equality, which math professors like to hate).  The expression is often some mathematical calculation (like X = 2*N), but more often (probably) it is simply a literal value (like X = 1) or another variable (like X = Y, an instance of duplication).  Because LET is optional, and BASIC runs faster without it, and programs end up smaller, it is almost never used (unless your professor is pedantic).
Unlike the BASIC is some other computers, compound assignment is not possible.  For example, in those other versions, LET X = Y = 0 would assign the value zero to two variables, X and Y.  In Commodore BASIC, LET only assigns one variable at a time.  The example just given would not generate an error on a CBM, however.  Instead it would first evaluate Y = 0 as a boolean expression (true or false) and the result would be assigned to the variable X.
While we're on the subject, Commodore BASIC evalutes an algebraic relation (such as X > Y) into either false (zero) or true (-1).  That is an example of creating a boolean result.  When Commodore BASIC interprets a number as boolean, however, any non-zero number is considered true (and zero is still considered false).
The expression must be the same (or convertable to) the same type of the variable, or an error occurs.  Attempts to assign a string expression to a numeric variable (or vice-vera) will generate TYPE MISMATCH ERROR, while a floating-point number too big for an integer type will instead generate an ILLEGAL QUANTITY ERROR.
The reserved variable TI$ can be assigned a value with LET.  Attempts to assign any other reserved variable (such as TI or ST) will generate SYNTAX ERROR.  When assigning a value to TI$, it must be a string of exactly 6 digits.  It is interpreted as a sexigesimal number (base 60) in the form of HHMMSS (hours, minutes, seconds), which means each pair of digits should have a value less than 60 (0 to 59).  Commodore BASIC does not enforce this, so setting a time of 1 minute 70 seconds "works".  Such a value will be interpretted as 2 minutes 10 seconds, as you might expect.  On the other hand, any value of 24 or more hours will not "work correctly".  For example, "250000" (25 hours, 0 minutes, 0 seconds) should be interpretted as 1 hour, 0 minutes, 0 seconds according to the logic of minutes and seconds mentioned previously.  But instead will be interpreted as 0 hours, 0 minutes, 0 seconds.  In short, any value greater/equal to 24 hours will be interpretted as zero!
10 LET X = 1  : REM verbose mode
20 X = 1      : REM typical
30 Y = X = 1  : REM assign 'true' (-1) to Y
40 X = Y > 1  : REM assign 'false' (0) to X
50 I% = 1.9   : REM assign 1 to I% (float to integer conversion)
60 W$ = "HELLO" : REM assign string
70 A(0) = 10  : REM assign element of array
80 F = 2*X+1  : REM evaluate expression 2*X+1 and assign to F
  Compare With  
  Contrast With  
=, MID$
  See Also  

© H2Obsession, 2014