title: Calculating the square numbers within a range (python)
body: <p>I want to be able to execute the following code: </p>
  
  <pre><code>for i in Squares(5, 50):
        print(i)
  </code></pre>
  
  <p>Now this is very easy to implement using a loop, however I want to use an iterator. </p>
  
  <p>So I have defined the following class:</p>
  
  <pre><code>import math
  
  class Squares(object):
  
      def __init__(self, start, stop):
         self.start = start
         self.stop = stop
  
      def __iter__(self): 
          return self
  
      def __next__(self):
          start = self.start
          stop = self.stop
          squareroot = math.sqrt(start)
  
          if self.start &gt; self.stop:
              raise StopIteration
  
          if squareroot == math.ceil(squareroot):
              start += 1
  </code></pre>
  
  <p>But at the moment this is returning <code>None</code> an infinite amount of times. This means the none must be because the <code>StopIteration</code> is being executed even when it shouldn't. I think my <code>if squareroot == math.ceil(squareroot):</code> condition is correct because I tested it separately, but I can't figure out what to change to get the output I want. Any help is appreciated.</p>
  
  <p>EDIT: For a code such as:</p>
  
  <pre><code>for i in Squares(4, 16):
      print(i)
  </code></pre>
  
  <p>I would expect the output to be:</p>
  
  <pre><code>4
  9
  16
  </code></pre>