Primes by Trial Division - DR LOGO
14 February 2018
For IBM PC LOGO, lists may not span lines.
TO PRIMES :N (LOCAL "PRIMES "COUNT "FOUND "I) MAKE "PRIMES [] MAKE "COUNT 2 MAKE "FOUND 0 LABEL "CONTINUE CATCH "NOTPRIME [ MAKE "I 1 REPEAT :FOUND [ IF REMAINDER :COUNT ITEM :I :PRIMES = 0 [ THROW "NOTPRIME ] [ MAKE "I (+ 1 :I) ] ] PRINT :COUNT MAKE "PRIMES (LPUT :COUNT :PRIMES) MAKE "FOUND (+ 1 :FOUND) ] MAKE "COUNT (+ 1 :COUNT) IF :FOUND < :N [ GO "CONTINUE ] END