title: For Loop in CasperJS
body: <p>I'm operating a listener in CasperJS that visits a few private websites &amp; waits for certain configurations of data.  Right now, this operates adequately, but not optimally, on a numbered For loop, along these lines:</p>
  
  <pre><code> for (var p = 20000;  p-- &gt; 0;) {
  
  // ... c.900 lines of code ....
  
  }
  </code></pre>
  
  <p>While loops &amp; Do-While loops don't work, due to scoping issues with several instances of Casper.then.  </p>
  
  <p>What I'm really looking to do is cron the code over a day timer, to operate between 6am and midnight, something like:</p>
  
  <pre><code>// as global variable
  
  function militarytime () {
                  var currentTime = new Date();
                  var hours = currentTime.getHours();
                  var minutes = currentTime.getMinutes();
                  var military = (hours*100)+minutes
                  return military;
  }
  
  var p = militarytime();
  
  // then within code,
  
  for (t=p; (t=p) &amp;&amp; (p&gt;600); t++)
  </code></pre>
  
  <p>This particular way of doing it (and I've tried many) just hangs in CasperJS.</p>
  
  <p>The code has been operating, suboptimally, in a production environment for several weeks, and I've been searching stackoverflow &amp; casperjs/api during that time to no avail.  Any suggestions?</p>
  
  <p>Thanks in advance.</p>