tic
n_to_find = 1000;

nprimesofar = 2;  % latest found prime
nprimesfound = 1; % we've found this many so far
n = 3;            % let's test this number next

while (nprimesfound < n_to_find)
    if (n<2)
        is_n_prime = false;
    elseif (n==2)
        is_n_prime = true;
    else
        is_n_prime = true;
        for i=2:floor(sqrt(n)) % efficiency #1
            if (mod(n,i)==0)
                is_n_prime = false;
                break
            end
        end
    end
    if (is_n_prime==true)
        nprimesfound = nprimesfound + 1;
        nprimesofar = n;
    end
    n = n + 2; % increment the next number to test for primeness
end
fprintf("the %dth prime number is %d\n", n_to_find, nprimesofar);
toc


