title: Mathematica -- generate a list of primes up to a limit
body: <p>What is the simplest function that generates a list of primes up to the argument?  Its not hard to come up with such a function, for instance:</p>
  
  <pre><code>foo[n_] := Block[{A = {}, p = 2},
             While[p &lt; n, A = Append[A, p]; p = NextPrime[p]];
             A]
  </code></pre>
  
  <p>However, this seems overly messy.  I would like to do something like</p>
  
  <pre><code>foo[n_] := Table[Prime[i], {i,2,???}]
  </code></pre>
  
  <p>Where ??? is the index of<code>NextPrime[n,-1]</code>.  Is this possible?</p>