Post by hydrophilic on Jul 27, 2014 17:21:46 GMT
I was looking at a disassembly of the BASIC ROM, and realized there is an undocumented feature with BEGIN.
The C128 System Guide and Programmer's Reference Guide both document its use similar to this...
IF condition THEN { lineNumber | statementT | BEGIN } [ : statementT ] ... [ : BEND ]
Well that is simplified your sanity, because it excludes ELSE.
Anyway, if you believe that, then the first statment following BEGIN (if on the same line) must be preceded with a colon ( : ). Every program I've seen or written has followed this convention. I don't see many BASIC 7 programs, so this mostly from my experience writing them
However, the BEGIN preposition is handled just like THEN/ELSE, in the sense that a colon is not needed before the first 'statementT'.
So here is an example of official Syntax:
and here is example of undocumented feature:
Now those are stupid examples for clarity's sake (you don't need BEGIN/BEND if it all fits on one line).
This feature works the same with BEGIN following ELSE (if you use else).
So you can save a byte, well, with the ROM. Many BASIC extensions will fail if you do not use a leading colon after BEGIN/ELSE/THEN. However the better ones (like BASIC 7.80) work just fine.
I don't know how much saving one byte would help, but if you use this trick all the time, you might save 10 or 16 bytes
I updated all the related pages in my BASIC Reference, namely BEGIN, BEND, ELSE, IF, and THEN.
The C128 System Guide and Programmer's Reference Guide both document its use similar to this...
IF condition THEN { lineNumber | statementT | BEGIN } [ : statementT ] ... [ : BEND ]
Well that is simplified your sanity, because it excludes ELSE.
Anyway, if you believe that, then the first statment following BEGIN (if on the same line) must be preceded with a colon ( : ). Every program I've seen or written has followed this convention. I don't see many BASIC 7 programs, so this mostly from my experience writing them
However, the BEGIN preposition is handled just like THEN/ELSE, in the sense that a colon is not needed before the first 'statementT'.
So here is an example of official Syntax:
IF A > 0 THEN BEGIN: PRINT A: BEND
and here is example of undocumented feature:
IF A > 0 THEN BEGIN PRINT A: BEND
Now those are stupid examples for clarity's sake (you don't need BEGIN/BEND if it all fits on one line).
This feature works the same with BEGIN following ELSE (if you use else).
So you can save a byte, well, with the ROM. Many BASIC extensions will fail if you do not use a leading colon after BEGIN/ELSE/THEN. However the better ones (like BASIC 7.80) work just fine.
I don't know how much saving one byte would help, but if you use this trick all the time, you might save 10 or 16 bytes
I updated all the related pages in my BASIC Reference, namely BEGIN, BEND, ELSE, IF, and THEN.