P = NEXTPRIME(100) DO WHILE (P.LE.150) ...stuff... P = NEXTPRIME(P) END DO