title: Return list of primes up to n using for loop
body: <p>I have just picked up learing python and I am trying to create a simple function which accepts an integer and returns a list of all primes from 2 to that integer. </p>
  
  <p>I have created the function but code doesn't seem to work. I have found solutions only for more efficient (and complex) methodes (like this one <a href="https://stackoverflow.com/questions/31045518/finding-prime-numbers-using-list-comprehention">Finding prime numbers using list comprehention</a>) for this problem which don't really help me in finding my mistake. </p>
  
  <pre><code>def list_of_primes(n):
      primes = []
      for y in range (2, n):
          for z in range(2, y):
              if y % x == 0:
                  continue
              else:
                  primes.append(y)
          primes.sort()
          return primes
  </code></pre>
  
  <p>What is wrong with the code?</p>