title: Python stops running after for loop with JSON
body: <p>I was doing a JSON tutorial with Python, and I realized the code is not running till the end.</p>
  <p>Here's the code:</p>
  <pre><code>#
  # Example file for parsing and processing JSON
  #
  
  import urllib.request  # instead of urllib2 like in Python 2.7
  import json
  
  
  def printResults(data):
      # Use the json module to load the string data into a dictionary
      theJSON = json.loads(data)
  
      # now we can access the contents of the JSON like any other Python object
      if &quot;title&quot; in theJSON[&quot;metadata&quot;]:
          print(theJSON[&quot;metadata&quot;][&quot;title&quot;])
  
      # output the number of events, plus the magnitude and each event name
      count = theJSON[&quot;metadata&quot;][&quot;count&quot;]
      print(str(count) + &quot; events recorded&quot;)
  
      # for each event, print the place where it occurred
      for i in theJSON[&quot;features&quot;]:
          print(i[&quot;properties&quot;][&quot;place&quot;])
  
      # # # code doesn't work from here # # #
      print(&quot;--------------\n&quot;)
  
      # # print the events that only have a magnitude greater than 4
      for i in theJSON[&quot;features&quot;]:
          if i[&quot;properties&quot;][&quot;mag&quot;] &gt;= 4.0:
              print(&quot;%2.1f&quot; % i[&quot;properties&quot;][&quot;mag&quot;], i[&quot;properties&quot;][&quot;place&quot;])
      print(&quot;--------------\n&quot;)
  
      # # print only the events where at least 1 person reported feeling something
      print(&quot;\n\nEvents that were felt:&quot;)
      for i in theJSON[&quot;features&quot;]:
          feltReports = i[&quot;properties&quot;][&quot;felt&quot;]
          if (feltReports != None):
              if (feltReports &gt; 0):
                  print(&quot;%2.1f&quot; % i[&quot;properties&quot;][&quot;mag&quot;], i[&quot;properties&quot;][&quot;place&quot;], &quot; reported &quot; + str(feltReports) + &quot; times&quot;)
  
  
  def main():
      # define a variable to hold the source URL
      # In this case we'll use the free data feed from the USGS
      # This feed lists all earthquakes for the last day larger than Mag 2.5
      urlData = &quot;https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson&quot;
  
      # Open the URL and read the data
      webUrl = urllib.request.urlopen(urlData)
      print(&quot;result code: &quot; + str(webUrl.getcode()))
      if (webUrl.getcode() == 200):
          data = webUrl.read().decode(&quot;utf-8&quot;)
          # print out our customized results
          printResults(data)
      else:
          print(&quot;Received an error from server, cannot retrieve results &quot; + str(webUrl.getcode()))
  
  
  if __name__ == &quot;__main__&quot;:
      main()
  </code></pre>
  <p>The code stops right after the first loop:</p>
  <pre><code>    # for each event, print the place where it occurred
      for i in theJSON[&quot;features&quot;]:
          print(i[&quot;properties&quot;][&quot;place&quot;])
  </code></pre>
  <p>I know it's not the indentation because I can run each for-loop separately, i.e. the second for-loop runs if I comment the first one.</p>
  <p>Is there something I'm missing here? Thanks!</p>