Primes by Trial Division - BBC BASIC
14 August 2016
BBC BASIC required several changes. This BASIC has a MODulus function, array indices are 1-based instead of 0-based, and the way the Applesoft reference version jumps in and out of the inner FOR loop causes the BBC BASIC stack to be exhausted after a couple iterations. So this version uses REPEAT/UNTIL.
10 DIM primes(100) 20 index=1 30 count=2 40 found=1 50 primes(index)=count 60 PRINT primes(index) 70 REPEAT 80 count=count+1 90 REPEAT 100 v=(count MOD primes(index)) 110 index=index+1 120 UNTIL v=0 OR index>found 130 IF v=0 THEN GOTO 170 140 PRINT count 150 primes(index)=count 160 found=found+1 170 index=1 180 UNTIL found=100