MATL, 16 bytes
2iq:"t`Qtt:\~z2>
This uses current release (10.1.0) of the language/compiler.
Try it online!
Explanation
This uses two nested loops. The outer one produces each prime, and the inner one increases 1 by 1 from latest found prime until the next prime is found.
To test for primality a modulo operation is used: x is prime if computing mod(x,k)
for k=1,2,...,x
produces no more than two zeros; that is, if only two numbers of the set 1,2,...,x
divide x
.
2 % push 2 (first prime) to the stack
i % input number, "n"
q: % generate vector [1,2,...,n-1]
" % "for" loop. This runs n-1 times, to find the n-1 primes after 2
t % duplicate top of the stack, which contains the latest found prime, "p"
` % "do...while" loop. This searches for the next prime
Q % increament top of stack by 1. This is the current candidate for next prime, "x"
t % duplicate top of the stack (x)
t: % produce vector [1,2,...,x]
\ % compute mod(x,k) for k=1,2,...,x
~2> % if that gives more than two zeros: x is not prime: we need another iteration
% implicitly end "do...while" loop
% implicitly end "for" loop
% implicitly display stack contents
n
can be 0 or will always be positive. \$\endgroup\$