Home > CBM > BASIC > Keywords > Let 180 Subpages: (divide), (equal), (less), (minus), (more), (multiply), (plus), (power), Abs, And, Append, Asc, Atn, Auto, Backup, Bank, Begin, Bend, Bload, Boot, Box, Bsave, Bump, Catalog, Char, Chr, Circle, Close, Clr, Cmd, Collect, Collision, Color, Concat, Cont, Copy, Cos, Data, Dclear, Dclose, Dec, Def, Delete, Dim, Directory, Dispose, Dload, Do, Dopen, Draw, Ds, Ds string, Dsave, Dverify, El, Else, End, Envelope, Er, Err, Exit, Exp, Fast, Fetch, Filter, Fn, For, Fre, Get, Get num, Getkey, Go, Gosub, Goto, Graphic, Gshape, Header, Help, Hex, If, Input, Input num, Instr, Int, Joy, Key, Left, Len, List, Load, Locate, Log, Loop, Mid, Monitor, Movspr, New, Next, Not, Off, On, Open, Or, Paint, Peek, Pen, Pi, Play, Pointer, Poke, Pos, Pot, Print, Print num, Pudef, Quit, Rclr, Rdot, Read, Record, Rem, Rename, Renumber, Restore, Resume, Return, Rgr, Right, Rlum, Rnd, Rreg, Rspcolor, Rsppos, Rsprite, Run, Rwindow, Save, Scale, Scnclr, Scratch, Sgn, Sin, Sleep, Slow, Sound, Spc, Sprcolor, Sprdef, Sprite, Sprsav, Sqr, Sshape, St, Stash, Step, Stop, Str, Swap, Sys, Tab, Tan, Tempo, Then, Ti, Ti string, To, Trap, Troff, Tron, Until, Using, Usr, Val, Verify, Vol, Wait, While, Width, Window, Xor |
| Keyword | Abbreviation | Token (hex) | Version(s) | Classification |
| LET | L{Shift+E} | 88 | 1.0 to 7.0 | Command and Statement |
[ LET ] variable = expression
| Parameters | Type | Legal Value(s) | Default Value | Note(s) |
| variable | Float, Integer, or String | any non-reserved name or TI$ | | |
| expression | 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 in 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 a signed 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!
Example:
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
100 TI$="014500" : REM 1:45 a.m.
110 TI$="134500" : REM 1:45 p.m.
|
(equal), BACKUP, COPY,
DIM, DEF, FETCH,
KEY, LOAD, MID$,
OPEN, SPRSAV, SSHAPE
DELETE, GRAPHIC CLR, GSHAPE,
HEADER, NEW, SCRATCH,
STASH
BASIC Expressions, FRE,
POINTER, Variable Format
© H2Obsession, 2014 |