title: Python If vs. While?
body: <p>I have a small file read routine and I want only the 1st 200 records I have it working but along the way I could not figure out what was wrong with using the "while" construct.
  This code works:</p>
  
  <pre><code>import csv, sys, zipfile
  sys.argv[0] = "/home/tom/Documents/REdata/AllListing1RES.zip"
  zip_file    = zipfile.ZipFile(sys.argv[0])
  items_file  = zip_file.open('AllListing1RES.txt', 'rU')
  rows = []
  for row_index, row in enumerate(csv.DictReader(items_file, dialect='excel', delimiter='\t')):
      if (row_index &lt; 200):
          rows.append(row)
      else : break
  </code></pre>
  
  <p>This code runs until it fails with an out of memory condition I would have thought it was equivalent?</p>
  
  <pre><code>import csv, sys, zipfile
  sys.argv[0] = "/home/tom/Documents/REdata/AllListing1RES.zip"
  zip_file    = zipfile.ZipFile(sys.argv[0])
  items_file  = zip_file.open('AllListing1RES.txt', 'rU')
  rows = []
  for row_index, row in enumerate(csv.DictReader(items_file, dialect='excel', delimiter='\t')):
      while (row_index &lt; 200):
          rows.append(row)
      else : break
  </code></pre>
  
  <p>so what would be the right construct using while? – </p>