Primes by Trial Division - Microsoft QBasic

17 August 2016
While Microsoft QBasic does allow programs with line numbers, idiomatically one is meant not to. So this version does not have them. Stack exhaustion was a problem for QBasic with the way the Applesoft version uses FOR/NEXT, so program flow has improved slightly as a side effect of dealing with that. The MODulus function is put to use as well.
SUB primes (n AS INTEGER)
count = 2
found = 0
index = 0
DIM prime(n - 1)
DO WHILE found < n
PRINT count
prime(found) = count
found = found + 1
NOTPRIME: count = count + 1
index = 0
DO
v = count MOD prime(index)
index = index + 1
LOOP UNTIL v = 0 OR index = found
IF v = 0 THEN GOTO NOTPRIME
LOOP
END SUB