Optimizing BASIC programs
- Every line can use the maximum amount of 80 bytes. If you enter commands in a line, fill it up to the end and then press ENTER, the commands are converted to internal format and you can go on adding some bytes
- String expressions at the end of a line can be written without the ending ": PRINT "Text
- Memory wasting 2-character name variables can be deleted with CLEAR <name>: CLEAR AB
- You never need to write a THEN after an IF command, you only have to write LET for a following variable operation: IF X=10 PRINT X but IF X=10 LET X=0
- Brackets round expressions are only necessary if the command needs more than one expression (like MID$(...), RIGHT$(...) but CHR$ 13)
- INPUT and PRINT can take more than one expression with "," but PRINT writes the values in two columns and you can't use a semicolon ";": PRINT X,Y or PRINT X;":";Y or INPUT "Text: ";X$,"Text2: ";Y$
- For small memory usage use the single-letter variables A-Z($)
- You can use DIM and CLEAR with more arrays with ",": DIM I$(0)*80,F(9) and CLEAR I$,F
- IF conditions can be written without brackets around them: IF X<9 AND y>10 ...
- IF accepts numbers and variables as conditions: <=0 false, >0 true: IF X PRINT...
- INKEY$ can be used like a normal string variable, i.e. in IF-conditions, it's empty when no key was pressed: IF INKEY$="" GOTO...
- GOTO and GOSUB can jump to numbers and letters which are given through variables: GOTO X$ (X$="A") or GOSUB X (X=10)
- ON ... GOTO/GOSUB can be used for case selections
- Operator sequence: INT, MDF, STR$, CHR$, ABS, SGN, PEEK, etc. are used before + - * / and logical operators
- Operators + - * / are executed before AND OR NOT
- PRINT with a ";" at the end of the expression counts the cursor one position forwards (breaks the line with PRINT)
- GOTO and GOSUB can jump to a string expression at the start of a line: GOTO "Calc" ... 100 "Calc"
- With some "," you can leave values in expressions unchanged while you change a certain one: OPEN ",,,,,&1A"
- The DEF key can start programs fast, labels can be written like this: 10 "A" CLS : WAIT 0 ...
- AREAD Var$ gives Var$ the value of the last printed value on the screen: DEF + A : 10 "A" AREAD I$
- You can save space when using PRINT = LPRINT to print your results. PRINT = PRINT stops this
- Variable definitions are faster with , as separator: A=1,B=2,C=4
The fastest commands:
- Use multiplication instead of power (^)
- FOR .. NEXT (STEP ..)
- ASC, CHR$
- AND, OR, NOT
- INT, MDF, SGN, ABS
- ON .. GOTO/GOSUB
- VAL, STR$
Copyright © Simon Lehmayr (Parts of my page were made with the help of Laurent Duveau)
If this page has no navigation, click here.