FizzBuzz in BASIC on a Sinclair ZX81

The Context

I went to the History of Computing museum in Cambridge on Mar 10, 2024 and there were lots of old computers, including a Sinclair ZX81.
notion image
The entire computer is tiny - the keyboard (which was not mechanical and horrible to type on) comes connected so you only need to connect a monitor.
The keyboard has the reserved keywords hardcoded which self-insert depending on the first key of a line you pressed. There were some other reserved keywords which you needed to press shift to access (e.g. to do an if/then clause you press u, which inserts the word IF, followed by the condition, then shift+3 to get a THEN printed - you cannot simply type out IF ... THEN ... ). You can also hold shift+new line to get into function mode to access functions like INT.
To start programming, you type the number of the line you want to overwrite and then press space. As there is no way to rearrange the lines dynamically (that I found), you typically increment your line numbers in 10s so you have room to insert new code you might need later without needing to re-write your entire program.

The Solution

I didn’t spend too long on it, but I ran into some problems:
  1. There was no modulo operator as far as I could find in the manual, which meant I ended up using the INT operator to check if there was a remainder.
    1. I could have used an algorithm to take away the divisor (3, 5, or 15) from I (the number I’m testing) until the remainder is less than the divisor and check if the remainder is 0, but the former solution seemed clearer and was easier to type.
  1. As far as I could see, there was no way to have an if block of more than one command. To run something like:
    1. if (/* condition */) { // command one // command two }
      You needed to do:
      IF /* condition */ THEN /* command one */ IF /* condition */ THEN /* command two */
  1. To do a for loop, you need to call NEXT I to jump back to the top of the next iteration.

The Code

notion image