| Home CBM ASCII-X BASIC Disk Commands Enter RUN mode Program Format Secret Variables Variable Format Expressions Keywords (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 Let 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 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 Syntax Tokens C128 D64plus Disk Escape Codes Hardware PCxface PETSCII Pet2asc Futurama IBM PC-AT Contact Games Glossary Hall of fame Hall of shame Miscellaneous Privacy policy Programming Twisty puzzles |
[ LET ] variable = expression
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! Example:
© H2Obsession, 2014 |