local fn IsPrime( n as NSUInteger ) as BOOL BOOL isPrime = YES NSUInteger i if n < 2 then exit fn = NO if n = 2 then exit fn = YES if n mod 2 == 0 then exit fn = NO for i = 3 to int(n^.5) step 2 if n mod i == 0 then exit fn = NO next end fn = isPrime local fn ExtensiblePrimes long c = 0, n = 2, count = 0, track = 0 printf @"The first 20 prime numbers are: " while ( c < 20 ) if ( fn IsPrime(n) ) printf @"%ld \b", n c++ end if n++ wend printf @"\n\nPrimes between 100 and 150 include: " for n = 100 to 150 if ( fn IsPrime(n) ) then printf @"%ld \b", n next printf @"\n\nPrimes beween 7,700 and 8,000 include: " c = 0 for n = 7700 to 8000 if ( fn IsPrime(n) ) then c += fn IsPrime(n) : printf @"%ld \b", n : count++ : track++ if count = 10 then print : count = 0 next printf @"There are %ld primes beween 7,700 and 8,000.", track printf @"\nThe 10,000th prime is: " c = 0 : n = 1 while ( c < 10000 ) n++ c += fn IsPrime(n) wend printf @"%ld", n end fn CFTimeInterval t t = fn CACurrentMediaTime fn ExtensiblePrimes printf @"\nCompute time: %.3f ms",(fn CACurrentMediaTime-t)*100 HandleEvents