Primes by Trial Division - Dartmouth True BASIC
28 August 2016
While Dartmouth True BASIC does allow programs with line numbers, idiomatically one is meant not to. So this version does not have them. Unfortunately True BASIC does not have statement labels like Microsoft QBasic does, so much finagling was necessary.
LET is supposedly optional, but in practice I found it necessary. By default array indices are 1-based, but one interesting feature of True BASIC is that you may DIMension an array with an arbitrary range of indices. But you may not DIMension an array with a variable, which ruled out implementing primes() as a SUBroutine. Variables are also supposedly global unless declared LOCAL, but again in practice I found that not to be the case. Variables are passed by reference to SUBroutines, though, so in the end, passing them as arguments was the solution.
Also, the syntax on the MODulus function is peculiar compared to all the other BASICs; though, strictly speaking, True BASIC's syntax is probably the correct one.
For NKR X3.113 BASIC, move the SUBroutine declaration to the beginning.
LET count=2 LET found=0 DIM primes(0 TO 99) CALL isprime(primes(found),count,found) DO WHILE found < 100 LET count=count+1 LET index=0 DO LET v=MOD(count,primes(index)) LET index=index+1 LOOP UNTIL v=0 OR index=found IF index=found THEN CALL isprime(primes(index),count,found) LOOP END SUB isprime(p,c,f) PRINT c LET p=c LET f=f+1 END SUB