title: Where to put variable to increase by 1 in def loop?
body: <p>I have this section of code:</p>
  
  <pre><code>if storagetypecheck1 == "Virtual":
          def storagecheck():
              d = 1
              dforid = str(1-d)
              while d &lt;= int(numcount): 
                  storageidprefix = "specimen" + "[" + dforid + "]"
                  driver.find_element_by_id(storageidprefix + ".storageContainerForSpecimen").click()
                  pag.press('a')
                  pag.press('enter')
                  time.sleep(1)
                  d = d + 1
                  storagecheck()
          storagecheck()
  </code></pre>
  
  <p>When the storage type of a webform is set to virtual, it will run and change the type to auto in the textboxes.</p>
  
  <p>The problem is that it has to do so with multiple textboxes which follow the format <code>specimen[x].storageContainerForSpecimen</code>.</p>
  
  <p>However, when I run this code, it just loops over and over without changing the value of <code>d</code> to <code>2</code>, <code>3</code>, etc.</p>
  
  <p>I tried having <code>d = 1</code> above the <code>if</code> statement, but then it says for line <code>dforid = str(1-d)</code> that <code>d</code> is not defined.</p>
  
  <p>Where should I put the <code>d = 1</code> expression so that it is able to be recognized by the <code>storagecheck()</code> loop while also being able to increase by <code>1</code> every loop?</p>