title: Need to run for loop and WaitFor in sync CasperJS
body: <p>I have a code as below</p>
  
  <pre><code>var casper = require('casper').create();
  casper.on('remote.message', function (msg) {
      this.echo(msg);
  });
  
  
  
  casper.start( &lt;&lt; some url &gt;&gt; , function () {
      this.echo(this.getTitle());
  
  
  });
  var resultObj = [];
  casper.thenClick("#AddToCart").then(function () {
      // scrape something else
  
      casper.options.waitTimeout = 100000;
  
      var objectOne = this.evaluate(someFunction, &lt;&lt; variables &gt;&gt; );
      //above function returns object
      casper.each(objectOne, function (self, obj) {
  
  
  
          var anotherObject = this.evaluate(anotherFunction, &lt;&lt; variables &gt;&gt; );
  
          self.waitFor(function check() {
  
              var result = this.evaluate(thirdFunction, obj);
              if (result != 'no') {
                  resultObj.push(result);
  
  
              }
  
              //  result = 'yes';
              return result != 'no';
              this.evaluate(function () {});
          }, function then() {
  
  
              console.log('done')
  
  
          });
  
  
      });
  });
  
  casper.run(function () {
      this.exit();
  });
  </code></pre>
  
  <p>It contains a loop (.each) followed by wait for. The problem that I am facing is the loop gets executed completely and then waitFor gets executed.
  How can I achieve them to be in sync?</p>