Fibonacci numbers in Tiny BASIC

I’ve just added a new example to TinyBASICBlazor, my experimental interactive Tiny BASIC web environment: a small program to generate the Fibonacci numbers.

The program is a simplified version (the original implementation also determines whether the elements of the sequence are prime numbers) of example 4.18 from the book Programming with BASIC (second edition) by Byron S. Gottfried, adapted for Tiny BASIC:

``````01  REM BASED ON EXAMPLE 4.18 FROM PROGRAMMING WITH BASIC BOOK BY BYRON S. GOTTFRIED
02  REM ADAPTED TO TINY BASIC BY MARCO'S RETROBITS
03  REM HTTPS://RETROBITS.ALTERVISTA.ORG    (ENGLISH)
04  REM HTTPS://SOMEBITSOFME.ALTERVISTA.ORG (ITALIAN)
05  REM HTTPS://RETROBITS.ITCH.IO
10  REM GENERATION OF FIBONACCI NUMBERS
20  PRINT "N= (3<=N<=23)";
30  INPUT N
35  IF N < 3 THEN GOTO 20
36  IF N > 23 THEN GOTO 20
40  PRINT
50  PRINT "GENERATION OF FIBONACCI NUMBERS"
60  PRINT
70  LET G=1
80  LET H=1
90  PRINT "I= ";1,"F= ";1
100 PRINT "I= ";2,"F= ";1
110 LET I=3
120   LET F=G+H
200   PRINT "I= ";I,"F= ";F
210   LET H=G
220   LET G=F
230 LET I=I+1
235 IF I<=N THEN GOTO 120
240 END``````

In the listing, the absence of the FOR loop is evident; it has been replaced with the less elegant IF and GOTO. Also, I limited the generated sequence to a maximum of 23 items, due to the precision (16 bits) of the numeric data type in this implementation of the Tiny BASIC interpreter. Below is the output of the generation of the first 20 Fibonacci numbers:

``````N= (3<=N<=23)? 20

GENERATION OF FIBONACCI NUMBERS

I= 1    F= 1
I= 2    F= 1
I= 3    F= 2
I= 4    F= 3
I= 5    F= 5
I= 6    F= 8
I= 7    F= 13
I= 8    F= 21
I= 9    F= 34
I= 10   F= 55
I= 11   F= 89
I= 12   F= 144
I= 13   F= 233
I= 14   F= 377
I= 15   F= 610
I= 16   F= 987
I= 17   F= 1597
I= 18   F= 2584
I= 19   F= 4181
I= 20   F= 6765
:``````

I decided to add this program purely nostalgic reasons, as it reminds me of computer science labs in my school days, many years ago.

You can run the “Fibonacci” program in TinyBASICBlazor by simply navigating to: retrobits.altervista.org/tinybasicblazor?p=fibonacci.